List of usage examples for weka.classifiers.evaluation ThresholdCurve getThresholdInstance
public static int getThresholdInstance(Instances tcurve, double threshold)
From source file:meka.core.Metrics.java
License:Open Source License
/** Get Data for Plotting PR and ROC curves. */ public static Instances curveDataMacroAveraged(int Y[][], double P[][]) { // Note: 'Threshold' contains the probability threshold that gives rise to the previous performance values. Instances curveData[] = curveData(Y, P); int L = curveData.length; int noNullIndex = -1; for (int i = 0; i < curveData.length; i++) { if (curveData[i] == null) { L--;/*w ww. j a v a2 s . c om*/ } else { if (noNullIndex == -1) { // checking for the first curveData that is not null (=does not consist of // only missing values or 0s) noNullIndex = i; } } } Instances avgCurve = new Instances(curveData[noNullIndex], 0); int D = avgCurve.numAttributes(); for (double t = 0.0; t < 1.; t += 0.01) { Instance x = (Instance) curveData[noNullIndex].instance(0).copy(); //System.out.println("x1\n"+x); boolean firstloop = true; for (int j = 0; j < L; j++) { // if there are only missing values in a column, curveData[j] is null if (curveData[j] == null) { continue; } int i = ThresholdCurve.getThresholdInstance(curveData[j], t); if (firstloop) { // reset for (int a = 0; a < D; a++) { x.setValue(a, curveData[j].instance(i).value(a) * 1. / L); } firstloop = false; } else { // add for (int a = 0; a < D; a++) { double v = x.value(a); x.setValue(a, v + curveData[j].instance(i).value(a) * 1. / L); } } } //System.out.println("x2\n"+x); avgCurve.add(x); } /* System.out.println(avgCurve); System.exit(1); // Average everything for (int i = 0; i < avgCurve.numInstances(); i++) { for(int j = 0; j < L; j++) { for (int a = 0; a < D; a++) { double o = avgCurve.instance(i).value(a); avgCurve.instance(i).setValue(a, o / L); } } } */ return avgCurve; }