You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2016/05/26 14:38:10 UTC
lucene-solr:branch_6x: LUCENE-7305 - use macro average in confusion
matrix metrics,
removed unused import in datasplitter (cherry picked from commit dc50b79)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 8c6493151 -> 55d854566
LUCENE-7305 - use macro average in confusion matrix metrics, removed unused import in datasplitter
(cherry picked from commit dc50b79)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/55d85456
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/55d85456
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/55d85456
Branch: refs/heads/branch_6x
Commit: 55d854566e1e3c14cd91d91f414469104c935103
Parents: 8c64931
Author: Tommaso Teofili <to...@apache.org>
Authored: Thu May 26 16:13:46 2016 +0200
Committer: Tommaso Teofili <to...@apache.org>
Committed: Thu May 26 16:25:11 2016 +0200
----------------------------------------------------------------------
.../utils/ConfusionMatrixGenerator.java | 49 +++++++-------------
1 file changed, 16 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/55d85456/lucene/classification/src/java/org/apache/lucene/classification/utils/ConfusionMatrixGenerator.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/utils/ConfusionMatrixGenerator.java b/lucene/classification/src/java/org/apache/lucene/classification/utils/ConfusionMatrixGenerator.java
index 3dd8ba8..65de801 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/utils/ConfusionMatrixGenerator.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/utils/ConfusionMatrixGenerator.java
@@ -175,7 +175,7 @@ public class ConfusionMatrixGenerator {
public double getPrecision(String klass) {
Map<String, Long> classifications = linearizedMatrix.get(klass);
double tp = 0;
- double fp = 0;
+ double den = 0; // tp + fp
if (classifications != null) {
for (Map.Entry<String, Long> entry : classifications.entrySet()) {
if (klass.equals(entry.getKey())) {
@@ -184,11 +184,11 @@ public class ConfusionMatrixGenerator {
}
for (Map<String, Long> values : linearizedMatrix.values()) {
if (values.containsKey(klass)) {
- fp += values.get(klass);
+ den += values.get(klass);
}
}
}
- return tp > 0 ? tp / (tp + fp) : 0;
+ return tp > 0 ? tp / den : 0;
}
/**
@@ -246,7 +246,7 @@ public class ConfusionMatrixGenerator {
if (this.accuracy == -1) {
double tp = 0d;
double tn = 0d;
- double fp = 0d;
+ double tfp = 0d; // tp + fp
double fn = 0d;
for (Map.Entry<String, Map<String, Long>> classification : linearizedMatrix.entrySet()) {
String klass = classification.getKey();
@@ -259,63 +259,46 @@ public class ConfusionMatrixGenerator {
}
for (Map<String, Long> values : linearizedMatrix.values()) {
if (values.containsKey(klass)) {
- fp += values.get(klass);
+ tfp += values.get(klass);
} else {
tn++;
}
}
}
- this.accuracy = (tp + tn) / (fp + fn + tp + tn);
+ this.accuracy = (tp + tn) / (tfp + fn + tn);
}
return this.accuracy;
}
/**
- * get the precision (see {@link #getPrecision(String)}) over all the classes.
+ * get the macro averaged precision (see {@link #getPrecision(String)}) over all the classes.
*
- * @return the precision as computed from the whole confusion matrix
+ * @return the macro averaged precision as computed from the confusion matrix
*/
public double getPrecision() {
- double tp = 0;
- double fp = 0;
+ double p = 0;
for (Map.Entry<String, Map<String, Long>> classification : linearizedMatrix.entrySet()) {
String klass = classification.getKey();
- for (Map.Entry<String, Long> entry : classification.getValue().entrySet()) {
- if (klass.equals(entry.getKey())) {
- tp += entry.getValue();
- }
- }
- for (Map<String, Long> values : linearizedMatrix.values()) {
- if (values.containsKey(klass)) {
- fp += values.get(klass);
- }
- }
+ p += getPrecision(klass);
}
- return tp > 0 ? tp / (tp + fp) : 0;
+ return p / linearizedMatrix.size();
}
/**
- * get the recall (see {@link #getRecall(String)}) over all the classes
+ * get the macro averaged recall (see {@link #getRecall(String)}) over all the classes
*
- * @return the recall as computed from the whole confusion matrix
+ * @return the recall as computed from the confusion matrix
*/
public double getRecall() {
- double tp = 0;
- double fn = 0;
+ double r = 0;
for (Map.Entry<String, Map<String, Long>> classification : linearizedMatrix.entrySet()) {
String klass = classification.getKey();
- for (Map.Entry<String, Long> entry : classification.getValue().entrySet()) {
- if (klass.equals(entry.getKey())) {
- tp += entry.getValue();
- } else {
- fn += entry.getValue();
- }
- }
+ r += getRecall(klass);
}
- return tp + fn > 0 ? tp / (tp + fn) : 0;
+ return r / linearizedMatrix.size();
}
@Override