use of de.lmu.ifi.dbs.elki.evaluation.outlier.OutlierROCCurve in project elki by elki-project.
the class AbstractOutlierAlgorithmTest method testAUC.
/**
* Test the AUC value for an outlier result.
*
* @param db Database
* @param positive Positive class name
* @param result Outlier result to process
* @param expected Expected AUC value
*/
protected void testAUC(Database db, String positive, OutlierResult result, double expected) {
OutlierROCCurve rocCurve = //
new ELKIBuilder<>(OutlierROCCurve.class).with(OutlierROCCurve.Parameterizer.POSITIVE_CLASS_NAME_ID, positive).build();
// Ensure the result has been added to the hierarchy:
ResultHierarchy hier = db.getHierarchy();
if (hier.numParents(result) < 1) {
hier.add(db, result);
}
// Compute ROC and AUC:
rocCurve.processNewResult(hier, result);
// Find the ROC results
Collection<OutlierROCCurve.ROCResult> rocs = ResultUtil.filterResults(hier, result, OutlierROCCurve.ROCResult.class);
assertTrue("No ROC result found.", !rocs.isEmpty());
double auc = rocs.iterator().next().getAUC();
assertFalse("More than one ROC result found.", rocs.size() > 1);
assertEquals("ROC value does not match.", expected, auc, 0.0001);
}
Aggregations