diff --git a/build.properties b/build.properties index aefb1c0..c13a62f 100644 --- a/build.properties +++ b/build.properties @@ -1,3 +1,3 @@ extension.version=2 extension.revision=0 -extension.update=002 +extension.update=003 diff --git a/resources/com/rapidminer/resources/i18n/OperatorsDocAnomalyDetection.xml b/resources/com/rapidminer/resources/i18n/OperatorsDocAnomalyDetection.xml index 8bf3990..619a339 100644 --- a/resources/com/rapidminer/resources/i18n/OperatorsDocAnomalyDetection.xml +++ b/resources/com/rapidminer/resources/i18n/OperatorsDocAnomalyDetection.xml @@ -209,6 +209,9 @@ guesses the two classes (normal or outlier), a ROC of 0.5 would be the result on average. As input, this operator expects the outlier score as well as the ground truth as labels. + Additionally the operator returns the precision and recall values for the whole input data. + The precision is calculated as true_positives/(true_positives+false_positives). + The recall is calculated as true_positives/(number of all outliers).

@@ -280,4 +283,4 @@

- \ No newline at end of file + diff --git a/src/de/dfki/madm/anomalydetection/evaluator/evaluation/ROCEvaluator.java b/src/de/dfki/madm/anomalydetection/evaluator/evaluation/ROCEvaluator.java index edd1669..85fcf72 100644 --- a/src/de/dfki/madm/anomalydetection/evaluator/evaluation/ROCEvaluator.java +++ b/src/de/dfki/madm/anomalydetection/evaluator/evaluation/ROCEvaluator.java @@ -57,7 +57,7 @@ public String toString() { public String getNormalClass() { return this.normal; } - + public Object[][] pre = null; //prediction / recall /** * The returned array has 4 columns denoting: false positive rate, * true positive rate/recall, precision and the decision threshold @@ -113,7 +113,7 @@ public Object[][] evaluate(String outlierString, Object[] labels, double[] res) if (j != size - 1 && outliers[j].outlierScore == outliers[j + 1].outlierScore) continue; Area += last[1] * ((double)falsePositive - last[0]) + (double)0.5 * ((double)falsePositive - last[0]) * ((double)truePositive - last[1]); - rocPoints.add(new double[] { falsePositive, truePositive , truePositive*1.0/(positive+negative), outliers[j].outlierScore}); + rocPoints.add(new double[] { falsePositive, truePositive , truePositive*1.0/(truePositive+falsePositive), outliers[j].outlierScore}); last[0] = falsePositive; last[1] = truePositive; @@ -127,13 +127,17 @@ public Object[][] evaluate(String outlierString, Object[] labels, double[] res) double totalArea = (double)positive * (double)negative; auc = Area / totalArea; - result = new Object[rocPoints.size()][4]; + result = new Object[rocPoints.size()][2]; int i = 0; + pre = new Object[rocPoints.size()][2]; for (double[] r : rocPoints) { result[i][0] = r[0] / negative; - result[i][1] = r[1] / positive; - result[i][2]= r[2]; - result[i++][3]= r[3]; + result[i++][1] = r[1] / positive; + } + i=0; + for(double[] r : rocPoints) { + pre[i][0] = r[2]; //precision = tp /(tp+fp) + pre[i++][1] = r[1] / positive; //recall = tp(so far) / all outlier } return result; diff --git a/src/de/dfki/madm/anomalydetection/operator/evaluation/ROCOperator.java b/src/de/dfki/madm/anomalydetection/operator/evaluation/ROCOperator.java index 2fbfdb4..b673418 100644 --- a/src/de/dfki/madm/anomalydetection/operator/evaluation/ROCOperator.java +++ b/src/de/dfki/madm/anomalydetection/operator/evaluation/ROCOperator.java @@ -55,6 +55,7 @@ public class ROCOperator extends Operator { private OutputPort exampleSetOutput = getOutputPorts().createPort("example set"); private OutputPort rocExampleSet = getOutputPorts().createPort("roc set"); private OutputPort aucOutput = getOutputPorts().createPort("auc"); + private OutputPort preOutput = getOutputPorts().createPort("pre"); private InputPort performanceInput = getInputPorts().createPort("performance"); private OutputPort performanceOutput = getOutputPorts().createPort("performance"); @@ -156,9 +157,14 @@ public void doWork() throws OperatorException { ROCEvaluator evaluator = new ROCEvaluator(); String outlierString = getParameterAsString(PARAMETER_LABEL); ExampleSet roc = (ExampleSet) ExampleSetFactory.createExampleSet(evaluator.evaluate(outlierString, labels, outliers)); + ExampleSet pre = (ExampleSet) ExampleSetFactory.createExampleSet(evaluator.pre); String norm = evaluator.getNormalClass(); - + roc.getAttributes().get("att1").setName("true_positive_rate"); + roc.getAttributes().get("att2").setName("false_positive_rate"); + pre.getAttributes().get("att1").setName("precision"); + pre.getAttributes().get("att2").setName("recall"); rocExampleSet.deliver(roc); + preOutput.deliver(pre); auc = evaluator.auc; Object[][] auc_ = { { auc } }; Object[] labels2 = { "AUC" };