【发布时间】:2015-10-27 19:10:09
【问题描述】:
我正在使用PCA 将矩阵m*n 简化为矩阵m*2。
我在我的项目中使用apache spark site 中的 sn-p,它可以工作。
import org.apache.spark.mllib.linalg.Matrix
import org.apache.spark.mllib.linalg.distributed.RowMatrix
val mat: RowMatrix = ...
// Compute the top 2 principal components.
val pc: Matrix = mat.computePrincipalComponents(2) // Principal components are stored in a local dense matrix.
// Project the rows to the linear space spanned by the top 2 principal components.
val projected: RowMatrix = mat.multiply(pc)
我还没有看到API 内部是否有获取旧数据的方法。 为了了解 PCA 选择了哪些列作为主成分。
是否有任何库函数可以做到这一点?
更新
如果 PCA 算法选择并转换了我的两列数据,我想知道如何验证此转换涉及的旧数据的哪些列?
示例
多维矩阵:
0 0 0 2 4
2 4 9 1 3
3 9 3 2 7
9 6 0 7 7
在 PCA 算法减少 2 维之后,我会得到这个:
-1.4 3
2 -4.0
3 -2.9
-0.9 6
也就是说,我如何了解 PCA 从原始数据中选择了哪些列 ,as principal components, 进行缩减?
提前致谢。
【问题讨论】:
标签: algorithm scala apache-spark pca