本文整理汇总了Java中weka.core.Utils.correlation方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.correlation方法的具体用法?Java Utils.correlation怎么用?Java Utils.correlation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Utils
的用法示例。
在下文中一共展示了Utils.correlation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Main method for testing this class
*
* @param args command line arguments
*/
public static void main(String[] args) {
try {
Instances orig = new Instances(new java.io.BufferedReader(
new java.io.FileReader(args[0])));
orig.setClassIndex(orig.numAttributes() - 1);
java.util.List<String> attNames = new java.util.ArrayList<String>();
for (int i = 0; i < orig.numAttributes(); i++) {
attNames.add(orig.attribute(i).name());
}
CSVToARFFHeaderMapTask arffTask = new CSVToARFFHeaderMapTask();
arffTask.setOptions(args);
// arffTask.setComputeSummaryStats(true);
for (int i = 0; i < orig.numInstances(); i++) {
arffTask.processRow(orig.instance(i).toString(), attNames);
}
Instances withSummary = arffTask.getHeader();
CSVToARFFHeaderReduceTask arffReduce = new CSVToARFFHeaderReduceTask();
List<Instances> instList = new ArrayList<Instances>();
instList.add(withSummary);
withSummary = arffReduce.aggregate(instList);
System.err.println(withSummary);
withSummary.setClassIndex(orig.classIndex());
CorrelationMatrixMapTask corrTask = new CorrelationMatrixMapTask();
corrTask.setup(withSummary);
for (int i = 0; i < orig.numInstances(); i++) {
corrTask.processInstance(orig.instance(i));
}
double[][] matrix = corrTask.getMatrix();
CorrelationMatrixRowReduceTask reduce =
new CorrelationMatrixRowReduceTask();
for (int i = 0; i < matrix.length; i++) {
List<double[]> toAgg = new ArrayList<double[]>();
toAgg.add(matrix[i]);
double[] computed = reduce.aggregate(i, toAgg, null, withSummary, true,
false, true);
for (int j = 0; j < matrix[i].length; j++) {
System.err.print(computed[j] + " ");
}
System.err.println();
}
System.err.println();
for (int i = 0; i < orig.numAttributes(); i++) {
double[] row = new double[i + 1];
for (int j = 0; j <= i; j++) {
if (i != orig.classIndex() && j != orig.classIndex()) {
if (i == j) {
row[j] = 1.0;
} else {
double[] ii = new double[orig.numInstances()];
double[] jj = new double[orig.numInstances()];
for (int k = 0; k < orig.numInstances(); k++) {
ii[k] = orig.instance(k).value(i);
jj[k] = orig.instance(k).value(j);
}
row[j] = Utils.correlation(ii, jj, orig.numInstances());
}
System.err.print(row[j] + " ");
}
}
System.err.println();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例2: checkAgainstUtilsCorr
import weka.core.Utils; //导入方法依赖的package包/类
protected void checkAgainstUtilsCorr(double[][] matrix, Instances orig,
Instances withSummary, boolean deleteClassIfSet) throws Exception {
CorrelationMatrixRowReduceTask reduce =
new CorrelationMatrixRowReduceTask();
double[][] finalM = new double[matrix.length][];
for (int i = 0; i < matrix.length; i++) {
List<double[]> toAgg = new ArrayList<double[]>();
toAgg.add(matrix[i]);
double[] computed = reduce.aggregate(i, toAgg, null, withSummary, true,
false, deleteClassIfSet);
// for (int j = 0; j < matrix[i].length; j++) {
// System.err.print(computed[j] + " ");
// }
finalM[i] = computed;
// System.err.println();
}
double[][] utilsC = new double[matrix.length][];
for (int i = 0; i < orig.numAttributes(); i++) {
double[] row = new double[i + 1];
for (int j = 0; j <= i; j++) {
if (i != orig.classIndex() && j != orig.classIndex()) {
if (i == j) {
row[j] = 1.0;
} else {
double[] ii = new double[orig.numInstances()];
double[] jj = new double[orig.numInstances()];
for (int k = 0; k < orig.numInstances(); k++) {
ii[k] = orig.instance(k).value(i);
jj[k] = orig.instance(k).value(j);
}
row[j] = Utils.correlation(ii, jj, orig.numInstances());
}
// System.err.print(row[j] + " ");
}
}
if (i != orig.classIndex()) {
utilsC[i] = row;
}
// System.err.println();
}
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < finalM[i].length; j++) {
double diff = Math.abs(finalM[i][j] - utilsC[i][j]);
assertTrue(diff < TOL);
}
}
}