本文整理汇总了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;
}
示例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;
}
示例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;
}
示例4: PrincipalComponents
import smile.projection.PCA; //导入依赖的package包/类
private PrincipalComponents(double[][] data, boolean useCorrelationMatrix) {
this.pca = new PCA(data, useCorrelationMatrix);
}
示例5: setProjection
import smile.projection.PCA; //导入依赖的package包/类
public PCA setProjection(int p) {
return pca.setProjection(p);
}