@@ -24,38 +24,43 @@ private[evaluation] trait BinaryClassificationMetricComputer extends Serializabl
24
24
def apply (c : BinaryConfusionMatrix ): Double
25
25
}
26
26
27
- /** Precision. */
27
+ /** Precision. Defined as 1.0 when there are no positive examples. */
28
28
private [evaluation] object Precision extends BinaryClassificationMetricComputer {
29
- override def apply (c : BinaryConfusionMatrix ): Double =
30
- if (c.numTruePositives + c.numFalsePositives == 0 ) {
31
- 0.0
29
+ override def apply (c : BinaryConfusionMatrix ): Double = {
30
+ val totalPositives = c.numTruePositives + c.numFalsePositives
31
+ if (totalPositives == 0 ) {
32
+ 1.0
32
33
} else {
33
- c.numTruePositives.toDouble / (c.numTruePositives + c.numFalsePositives)
34
+ c.numTruePositives.toDouble / totalPositives
34
35
}
36
+ }
35
37
}
36
38
37
- /** False positive rate. */
39
+ /** False positive rate. Defined as 0.0 when there are no negative examples. */
38
40
private [evaluation] object FalsePositiveRate extends BinaryClassificationMetricComputer {
39
- override def apply (c : BinaryConfusionMatrix ): Double =
41
+ override def apply (c : BinaryConfusionMatrix ): Double = {
40
42
if (c.numNegatives == 0 ) {
41
43
0.0
42
44
} else {
43
45
c.numFalsePositives.toDouble / c.numNegatives
44
46
}
47
+ }
45
48
}
46
49
47
- /** Recall. */
50
+ /** Recall. Defined as 0.0 when there are no positive examples. */
48
51
private [evaluation] object Recall extends BinaryClassificationMetricComputer {
49
- override def apply (c : BinaryConfusionMatrix ): Double =
52
+ override def apply (c : BinaryConfusionMatrix ): Double = {
50
53
if (c.numPositives == 0 ) {
51
54
0.0
52
55
} else {
53
56
c.numTruePositives.toDouble / c.numPositives
54
57
}
58
+ }
55
59
}
56
60
57
61
/**
58
- * F-Measure.
62
+ * F-Measure. Defined as 0 if both precision and recall are 0. EG in the case that all examples
63
+ * are false positives.
59
64
* @param beta the beta constant in F-Measure
60
65
* @see http://en.wikipedia.org/wiki/F1_score
61
66
*/
0 commit comments