title: How to prepare data into a LibSVM format from DataFrame?
body: <p>I want to make libsvm format, so I made dataframe to the desired format, but I do not know how to convert to libsvm format. The format is as shown in the figure. I hope that the desired libsvm type is <strong>user item:rating</strong> . If you know what to do in the current situation :</p>
  
  <pre class="lang-scala prettyprint-override"><code>val ratings = sc.textFile(new File("/user/ubuntu/kang/0829/rawRatings.csv").toString).map { line =&gt;
       val fields = line.split(",")
        (fields(0).toInt,fields(1).toInt,fields(2).toDouble)
  }
  val user = ratings.map{ case (user,product,rate) =&gt; (user,(product.toInt,rate.toDouble))}
  val usergroup = user.groupByKey 
  
  val data =usergroup.map{ case(x,iter) =&gt; (x,iter.map(_._1).toArray,iter.map(_._2).toArray)}
  
  val data_DF = data.toDF("user","item","rating")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/RsZaJ.jpg" alt="DATAFRAME FIGURE"></p>
  
  <p>I am using Spark 2.0.</p>