Machine Learning prelude - Create vector
Code
package MLlibDemo.vectorDemo
import org.apache.spark.ml.linalg.Vectors
object VectorDemo2 {
def main(args: Array[String]): Unit = {
val p1 = "30,172,58,200"
val featureArray = p1.split(",")
val features: Array[Double] = featureArray.map(_.toDouble)
val denseVector = Vectors.dense(features)
val size = denseVector.size
val array = denseVector.toArray
val fature2 = denseVector(2)
val sparse = denseVector.toSparse
val argmax = denseVector.argmax
val vector = Vectors.sparse(6, Array(0, 2), Array(30, 58))
val argmax1 = vector.argmax
val array1 = vector.toArray
val dense = vector.toDense
}
}