use of edu.cmu.tetrad.util.RocCalculator in project tetrad by cmu-phil.
the class BayesUpdaterClassifierEditor method showRocCurve.
private void showRocCurve() {
int tabIndex = -1;
for (int i = 0; i < getTabbedPane().getTabCount(); i++) {
if ("ROC Plot".equals(getTabbedPane().getTitleAt(i))) {
getTabbedPane().remove(i);
tabIndex = i;
this.rocPlot = null;
this.saveRoc.setEnabled(false);
}
}
double[][] marginals = getClassifier().getMarginals();
int ncases = getClassifier().getNumCases();
boolean[] inCategory = new boolean[ncases];
DataSet testData = getClassifier().getTestData();
DiscreteVariable targetVariable = classifier.getTargetVariable();
String targetName = targetVariable.getName();
Node variable2 = testData.getVariable(targetName);
int varIndex = testData.getVariables().indexOf(variable2);
// If the target is not in the data set, don't compute a ROC plot.
if (varIndex == -1) {
return;
}
String category = (String) getCategoryDropdown().getSelectedItem();
DiscreteVariable variable = (DiscreteVariable) variable2;
int catIndex = variable.getIndex(category);
for (int i = 0; i < inCategory.length; i++) {
inCategory[i] = (testData.getInt(i, varIndex) == catIndex);
}
double[] scores = marginals[catIndex];
RocCalculator rocc = new RocCalculator(scores, inCategory, RocCalculator.ASCENDING);
double[][] points = rocc.getScaledRocPlot();
double area = rocc.getAuc();
NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
String info = "AUC = " + nf.format(area);
String title = "ROC Plot, " + classifier.getTargetVariable() + " = " + category;
RocPlot plot = new RocPlot(points, title, info);
this.rocPlot = plot;
this.saveRoc.setEnabled(true);
if (tabIndex == -1) {
getTabbedPane().add("ROC Plot", plot);
} else {
getTabbedPane().add(plot, tabIndex);
getTabbedPane().setTitleAt(tabIndex, "ROC Plot");
}
}
Aggregations