Repository: incubator-hivemall Updated Branches: refs/heads/master aafd0f1e3 -> d53e71a3c
Close #85: [HIVEMALL-115] Fix ranking AUC for all TP/FP recommendation Project: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/commit/d53e71a3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/tree/d53e71a3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/diff/d53e71a3 Branch: refs/heads/master Commit: d53e71a3cf71d2c211e0c798e3de50ac65a05235 Parents: aafd0f1 Author: Takuya Kitazawa <[email protected]> Authored: Thu Jun 15 17:59:41 2017 +0900 Committer: Makoto Yui <[email protected]> Committed: Thu Jun 15 17:59:41 2017 +0900 ---------------------------------------------------------------------- .../java/hivemall/evaluation/BinaryResponsesMeasures.java | 5 +++++ .../hivemall/evaluation/BinaryResponsesMeasuresTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/d53e71a3/core/src/main/java/hivemall/evaluation/BinaryResponsesMeasures.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/hivemall/evaluation/BinaryResponsesMeasures.java b/core/src/main/java/hivemall/evaluation/BinaryResponsesMeasures.java index fc25882..81cf075 100644 --- a/core/src/main/java/hivemall/evaluation/BinaryResponsesMeasures.java +++ b/core/src/main/java/hivemall/evaluation/BinaryResponsesMeasures.java @@ -191,6 +191,11 @@ public final class BinaryResponsesMeasures { // # of all possible <TP, FP> pairs int nPairs = nTruePositive * (recommendSize - nTruePositive); + // if there is no TP or no FP, it's meaningless for this metric (i.e., AUC=0.5) + if (nPairs == 0) { + return 0.5d; + } + // AUC can equivalently be calculated by counting the portion of correctly ordered pairs return (double) nCorrectPairs / nPairs; } http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/d53e71a3/core/src/test/java/hivemall/evaluation/BinaryResponsesMeasuresTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/hivemall/evaluation/BinaryResponsesMeasuresTest.java b/core/src/test/java/hivemall/evaluation/BinaryResponsesMeasuresTest.java index 800eb6c..b78bf0e 100644 --- a/core/src/test/java/hivemall/evaluation/BinaryResponsesMeasuresTest.java +++ b/core/src/test/java/hivemall/evaluation/BinaryResponsesMeasuresTest.java @@ -102,6 +102,16 @@ public class BinaryResponsesMeasuresTest { actual = BinaryResponsesMeasures.AUC(rankedList, groundTruth, 2); Assert.assertEquals(1.0d, actual, 0.0001d); + + // meaningless case I: all TPs + List<Integer> groundTruthAllTruePositive = Arrays.asList(1, 3, 2, 6); + actual = BinaryResponsesMeasures.AUC(rankedList, groundTruthAllTruePositive, rankedList.size()); + Assert.assertEquals(0.5d, actual, 0.0001d); + + // meaningless case II: all FPs + List<Integer> groundTruthAllFalsePositive = Arrays.asList(7, 8, 9, 10); + actual = BinaryResponsesMeasures.AUC(rankedList, groundTruthAllFalsePositive, rankedList.size()); + Assert.assertEquals(0.5d, actual, 0.0001d); } }
