SVD with Spark ML

Let's implement SVD code using the SparkML library:

import org.apache.spark.mllib.linalg.Matriximport org.apache.spark.mllib.linalg.Vectorsimport org.apache.spark.mllib.linalg.Vectorimport org.apache.spark.mllib.linalg.distributed.RowMatriximport org.apache.spark.mllib.linalg.SingularValueDecompositionval data = Array(Vectors.dense(2.0, 1.0, 75.0, 18.0, 1.0,2),Vectors.dense(0.0, 1.0, 21.0, 28.0, 2.0,4),Vectors.dense(0.0, 1.0, 32.0, 61.0, 5.0,10),Vectors.dense(0.0, 1.0, 56.0, 39.0, 2.0,4),Vectors.dense(1.0, 1.0, 73.0, 81.0, 3.0,6),Vectors.dense(0.0, 1.0, 97.0, 59.0, 7.0,14))val rows = sc.parallelize(data)val mat: RowMatrix = new RowMatrix(rows)val svd: SingularValueDecomposition[RowMatrix, Matrix] = mat.computeSVD(3, computeU ...

Get Artificial Intelligence for Big Data now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.