title: Create LabeledPoint from sparse vector in spark
body: <p>I created a feature vector in a DataFrame in spark/scala using the VectorAssembler. So far everything works fine. Now I want to create LabeledPoints from the label and the sparse vector.</p>
  
  <pre><code>val labeledPoints = featureDf.map{r=&gt;
    val label = r(0).toString.toDouble + r(1).toString.toDouble + r(2).toString.toDouble
    val features = r(r.size-1)
    LabeledPoint(label, Vectors.sparse(features))
  
  }
  </code></pre>
  
  <p>But that doesn't work. I get a compile error. The error is:</p>
  
  <pre><code>overloaded method value sparse with alternatives:
  (size: Int,elements: Iterable[(Integer,java.lang.Double)])org.apache.spark.mllib.linalg.Vector
  &lt;and&gt;
  (size: Int,elements: Seq[(Int, scala.Double)])org.apache.spark.mllib.linalg.Vector
  &lt;and&gt;
  (size: Int,indices: Array[Int],values:Array[scala.Double])org.apache.spark.mllib.linalg.Vector
  cannot be applied to (Any)
  </code></pre>
  
  <p>I already tried to cast the vector with <code>val features = r(r.size-1).asInstanceOf[Vector]</code> and so on but nothing works. Does anyone know how to solve this problem?</p>
  
  <p>Thanks in advance!</p>