我很想将我的org.apache.spark.mllib.linalg.Matrix转换为org.apache.spark.mllib.linalg.distributed.RowMatrix。
我可以这样做:
val xx = X.computeGramianMatrix() //xx is type org.apache.spark.mllib.linalg.Matrix
val xxs = xx.toString()
val xxr = xxs.split("\n").map(row => row.replace(" "," ").replace(" "," ").replace(" "," ").replace(" "," ").replace(" ",",").split(","))
val xxp = sc.parallelize(xxr)
val xxd = xxp.map(ar => Vectors.dense(ar.map(elm => elm.toDouble)))
val xxrm: RowMatrix = new RowMatrix(xxd)
然而,这真的很粗糙,也是一种完全的黑客行为。有人能展示给我更好的方法吗?
请注意,我正在使用Spark版本1.3.0。
new DenseVector
有特定的原因吗? - dennlinger