Skip to content

Commit

Permalink
Precision and Recall added
Browse files Browse the repository at this point in the history
ROC output renamed
  • Loading branch information
JohannGebhardt committed Sep 4, 2013
1 parent e94eb2f commit 98d1123
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
extension.version=2
extension.revision=0
extension.update=002
extension.update=003
Original file line number Diff line number Diff line change
Expand Up @@ -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).
</p>
</help>
</operator>
Expand Down Expand Up @@ -280,4 +283,4 @@
</p>
</help>
</operator>
</operatorHelp>
</operatorHelp>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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" };
Expand Down

0 comments on commit 98d1123

Please sign in to comment.