当前位置: 首页>>代码示例>>Java>>正文


Java PCA类代码示例

本文整理汇总了Java中smile.projection.PCA的典型用法代码示例。如果您正苦于以下问题:Java PCA类的具体用法?Java PCA怎么用?Java PCA使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PCA类属于smile.projection包,在下文中一共展示了PCA类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: learn

import smile.projection.PCA; //导入依赖的package包/类
public JComponent learn() {
    JPanel pane = new JPanel(new GridLayout(1, 2));

    PCA pca = new PCA(data);
    pca.setProjection(50);
    double[][] X = pca.project(data);
    long clock = System.currentTimeMillis();
    TSNE tsne = new TSNE(X, 2, perplexity, 200, 1000);
    System.out.format("Learn t-SNE from %d samples in %dms\n", data.length, System.currentTimeMillis() - clock);

    double[][] y = tsne.getCoordinates();

    PlotCanvas plot = new PlotCanvas(Math.colMin(y), Math.colMax(y));

    for (int i = 0; i < y.length; i++) {
        plot.point(pointLegend, Palette.COLORS[labels[i]], y[i]);
    }

    plot.setTitle("tSNE");
    pane.add(plot);

    return pane;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:24,代码来源:TSNEDemo.java

示例2: learn

import smile.projection.PCA; //导入依赖的package包/类
@Override
public JComponent learn() {
    double[][] data = dataset[datasetIndex].toArray(new double[dataset[datasetIndex].size()][]);
    String[] names = dataset[datasetIndex].toArray(new String[dataset[datasetIndex].size()]);
    if (names[0] == null) {
        names = null;
    }
    boolean cor = corBox.getSelectedIndex() != 0;

    long clock = System.currentTimeMillis();
    PCA pca = new PCA(data, cor);
    System.out.format("Learn PCA from %d samples in %dms\n", data.length, System.currentTimeMillis()-clock);

    JPanel pane = new JPanel(new GridLayout(1, 2));
    PlotCanvas scree = PlotCanvas.screeplot(pca);
    scree.setTitle("Variance");
    pane.add(scree);

    pca.setProjection(3);
    double[][] y = pca.project(data);

    PlotCanvas plot = new PlotCanvas(Math.colMin(y), Math.colMax(y));
    if (names != null) {
        plot.points(y, names);
    } else if (dataset[datasetIndex].responseAttribute() != null) {
        int[] labels = dataset[datasetIndex].toArray(new int[dataset[datasetIndex].size()]);
        for (int i = 0; i < y.length; i++) {
            plot.point(pointLegend, Palette.COLORS[labels[i]], y[i]);
        }
    } else {
        plot.points(y, pointLegend);
    }

    plot.setTitle("Scatter Plot");
    pane.add(plot);
    return pane;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:38,代码来源:PCADemo.java

示例3: screeplot

import smile.projection.PCA; //导入依赖的package包/类
/**
 * Create a scree plot for PCA.
 * @param pca principal component analysis object.
 */
public static PlotCanvas screeplot(PCA pca) {
    int n = pca.getVarianceProportion().length;

    double[] lowerBound = {0, 0.0};
    double[] upperBound = {n + 1, 1.0};

    PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound, false);
    canvas.setAxisLabels("Principal Component", "Proportion of Variance");

    String[] labels = new String[n];
    double[] x = new double[n];
    double[][] data = new double[n][2];
    double[][] data2 = new double[n][2];
    for (int i = 0; i < n; i++) {
        labels[i] = "PC" + (i + 1);
        x[i] = i + 1;
        data[i][0] = x[i];
        data[i][1] = pca.getVarianceProportion()[i];
        data2[i][0] = x[i];
        data2[i][1] = pca.getCumulativeVarianceProportion()[i];
    }

    LinePlot plot = new LinePlot(data);
    plot.setID("Variance");
    plot.setColor(Color.RED);
    plot.setLegend('@');
    canvas.add(plot);
    canvas.getAxis(0).addLabel(labels, x);

    LinePlot plot2 = new LinePlot(data2);
    plot2.setID("Cumulative Variance");
    plot2.setColor(Color.BLUE);
    plot2.setLegend('@');
    canvas.add(plot2);

    return canvas;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:42,代码来源:PlotCanvas.java

示例4: PrincipalComponents

import smile.projection.PCA; //导入依赖的package包/类
private PrincipalComponents(double[][] data, boolean useCorrelationMatrix) {
    this.pca = new PCA(data, useCorrelationMatrix);
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:4,代码来源:PrincipalComponents.java

示例5: setProjection

import smile.projection.PCA; //导入依赖的package包/类
public PCA setProjection(int p) {
    return pca.setProjection(p);
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:4,代码来源:PrincipalComponents.java


注:本文中的smile.projection.PCA类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。