title: How to encode a Dataset for linear regression in Spark with Java?
body: <p>I have a <code>Dataset&lt;Row&gt;</code> with 3 colums and i want to modify for make a linear regression.</p>
  
  <p>My colums are <code>[id , x, y]</code> and i want a linear regression for each id;</p>
  
  <p>For example:</p>
  
  <pre><code>[1 , 1005, 0.29]   
  [1 , 1006, 0.46]  
  [1 , 1007, 0.29]
  [2 , 1000, 0.68]
  [2 , 1010, 0.50]
  </code></pre>
  
  <p>How i can create a LabeledPoint from this data?</p>
  
  <p>Do i need my data in this way?:</p>
  
  <pre><code>(0.29, (1, [1005,1007]))
  (0.46, (1, [1006]))
  (0.68, (2, [1000]))
  (0.50, (2, [1010]))
  </code></pre>
  
  <p>I know how to modify until this point:</p>
  
  <pre class="lang-java prettyprint-override"><code>JavaRDD&lt;Row&gt; datardd = dataset.toJavaRDD();
  JavaPairRDD&lt;Integer, Tuple2&lt;Double,Double&gt;&gt; datapairrdd =
             datardd.mapToPair(new PairFunction&lt;Row, Integer, Tuple2&lt;Double, Double&gt;&gt;(){
              @Override
              public Tuple2&lt;Integer, Tuple2&lt;Double, Double&gt;&gt; call(Row row) throws Exception {
                      return new Tuple2&lt;&gt;(new Integer(row.getString(0)), new Tuple2&lt;&gt;(new Double(row.getString(1)), new Double(row.getString(2))));
              }
          });
  JavaPairRDD&lt;Integer, Iterable&lt;Tuple2&lt;Double, Double&gt;&gt;&gt; data = pairrdd.groupByKey();
  </code></pre>
  
  <p>So my data now is:</p>
  
  <pre><code>    (1, [(1005,0.29), (1006,0.46), (1007, 0.29)])
      (2, [(1000,0.68), (1010,0.50)])
  </code></pre>
  
  <p>But from here i'm stuck...</p>