2012-05-15 10 views
8

JavaでPCAを実装する必要があります。私は、文書化され、実用的で使いやすいものを見つけることに興味があります。どんな勧告?JavaでのPCAの実装

答えて

8

ここには、PCA Classがあります。

このクラスには、バリマックスローテーションによる基本的な主成分分析に必要なメソッドが含まれています。共分散または相関martixのいずれかを使用した分析では、オプションを使用できます。モンテカルロシミュレーションを用いた並列解析が行われる。モンテカルロ固有値パーセンタイルより大きい、またはモンテカルロ固有値より大きい固有値に基づく抽出基準が利用可能である。実際に

3

チェックhttp://weka.sourceforge.net/doc.stable/weka/attributeSelection/PrincipalComponents.html WEKAは、PCAと一緒に使用することができ、他の多くのアルゴリズムを持っており、また随時多くのアルゴリズムを追加してWEKA。だから私は、もしあなたがweka apiに切り替えると、javaに取り組んでいる。

+3

リンクが無効です。リンクのみで質問に回答しないようにしてください。これらの質問は、期限切れとなる可能性があります。 – Iancovici

8

Java用の主成分分析の実装が多数あります。

  1. Apacheのスパーク:https://spark.apache.org/docs/2.1.0/mllib-dimensionality-reduction.html#principal-component-analysis-pca

    SparkConf conf = new SparkConf().setAppName("PCAExample").setMaster("local"); 
    try (JavaSparkContext sc = new JavaSparkContext(conf)) { 
        //Create points as Spark Vectors 
        List<Vector> vectors = Arrays.asList(
          Vectors.dense(-1.0, -1.0), 
          Vectors.dense(-1.0, 1.0), 
          Vectors.dense(1.0, 1.0)); 
    
        //Create Spark MLLib RDD 
        JavaRDD<Vector> distData = sc.parallelize(vectors); 
        RDD<Vector> vectorRDD = distData.rdd(); 
    
        //Execute PCA Projection to 2 dimensions 
        PCA pca = new PCA(2); 
        PCAModel pcaModel = pca.fit(vectorRDD); 
        Matrix matrix = pcaModel.pc(); 
    } 
    
  2. ND4J:http://nd4j.org/doc/org/nd4j/linalg/dimensionalityreduction/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); 
    
  3. アパッチ・コモンズ数学(シングルスレッド; NOフレームワーク)

    //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); 
    

注:プリンシパルコンポーネントの検索にも使用できる特異値分解には、同等の実装があります。