Java中的PCA实现 [英] PCA Implementation in Java
本文介绍了Java中的PCA实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要用Java实现PCA.我感兴趣的是找到有据可查,实用且易于使用的东西.有什么建议吗?
I need implementation of PCA in Java. I am interested in finding something that's well documented, practical and easy to use. Any recommendations?
推荐答案
现在有许多针对Java的主成分分析实现.
There are now a number of Principal Component Analysis implementations for Java.
-
ND4J: https://javadoc.io/doc/org.nd4j/nd4j-api/1.0.0-beta7/org/nd4j/linalg/Dimensionityreduction/PCA.html
//Create points as NDArray instances List<INDArray> ndArrays = Arrays.asList( new NDArray(new float [] {-1.0F, -1.0F}), new NDArray(new float [] {-1.0F, 1.0F}), new NDArray(new float [] {1.0F, 1.0F})); //Create matrix of points (rows are observations; columns are features) INDArray matrix = new NDArray(ndArrays, new int [] {3,2}); //Execute PCA - again to 2 dimensions INDArray factors = PCA.pca_factor(matrix, 2, false);
-
Apache Commons Math(单线程;无框架)
Apache Commons Math (single threaded; no framework)
//create points in a double array double[][] pointsArray = new double[][] { new double[] { -1.0, -1.0 }, new double[] { -1.0, 1.0 }, new double[] { 1.0, 1.0 } }; //create real matrix RealMatrix realMatrix = MatrixUtils.createRealMatrix(pointsArray); //create covariance matrix of points, then find eigen vectors //see https://stats.stackexchange.com/questions/2691/making-sense-of-principal-component-analysis-eigenvectors-eigenvalues Covariance covariance = new Covariance(realMatrix); RealMatrix covarianceMatrix = covariance.getCovarianceMatrix(); EigenDecomposition ed = new EigenDecomposition(covarianceMatrix);
请注意,奇异值分解(也可用于查找主要成分)具有等效的实现.
Note, Singular Value Decomposition, which can also be used to find Principal Components, has equivalent implementations.
这篇关于Java中的PCA实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文