Skip to content

Commit

Permalink
set the precision of empty labset to 0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
coderxiang committed Oct 20, 2014
1 parent d64c120 commit be6645e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RankingMetrics[T: ClassTag](predictionAndLabels: RDD[(Array[T], Array[T])]
* computed as #(relevant items retrived) / k. This formula also applies when the size of the
* ground truth set is less than k.
*
* If a query has an empty ground truth set, one will be returned together with a log warning.
* If a query has an empty ground truth set, zero will be returned together with a log warning.
*
* See the following paper for detail:
*
Expand All @@ -67,7 +67,7 @@ class RankingMetrics[T: ClassTag](predictionAndLabels: RDD[(Array[T], Array[T])]
}
if (labSet.size == 0) {
logWarning("Empty ground truth set, check input data")
1.0
0.0
} else {
cnt.toDouble / k
}
Expand All @@ -76,7 +76,7 @@ class RankingMetrics[T: ClassTag](predictionAndLabels: RDD[(Array[T], Array[T])]

/**
* Returns the mean average precision (MAP) of all the queries.
* If a query has an empty ground truth set, the average precision will be 1.0 and a log
* If a query has an empty ground truth set, the average precision will be zero and a log
* warining is generated.
*/
lazy val meanAveragePrecision: Double = {
Expand All @@ -97,7 +97,7 @@ class RankingMetrics[T: ClassTag](predictionAndLabels: RDD[(Array[T], Array[T])]
}
if (labSetSize == 0) {
logWarning("Empty ground truth set, check input data")
1.0
0.0
} else {
precSum / labSet.size
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class RankingMetricsSuite extends FunSuite with LocalSparkContext {
val metrics = new RankingMetrics(predictionAndLabels)
val map = metrics.meanAveragePrecision

assert(metrics.precisionAt(1) ~== 2.0/3 absTol eps)
assert(metrics.precisionAt(2) ~== 2.0/3 absTol eps)
assert(metrics.precisionAt(3) ~== 2.0/3 absTol eps)
assert(metrics.precisionAt(4) ~== 1.75/3 absTol eps)
assert(metrics.precisionAt(5) ~== 0.6 absTol eps)
assert(metrics.precisionAt(10) ~== 0.6 absTol eps)
assert(metrics.precisionAt(15) ~== 23.0/45 absTol eps)

assert(map ~== 0.6883598 absTol eps)
assert(metrics.precisionAt(1) ~== 1.0/3 absTol eps)
assert(metrics.precisionAt(2) ~== 1.0/3 absTol eps)
assert(metrics.precisionAt(3) ~== 1.0/3 absTol eps)
assert(metrics.precisionAt(4) ~== 0.75/3 absTol eps)
assert(metrics.precisionAt(5) ~== 0.8/3 absTol eps)
assert(metrics.precisionAt(10) ~== 0.8/3 absTol eps)
assert(metrics.precisionAt(15) ~== 8.0/45 absTol eps)

assert(map ~== 0.355026 absTol eps)

assert(metrics.ndcgAt(3) ~== 1.0/3 absTol eps)
assert(metrics.ndcgAt(5) ~== 0.328788 absTol eps)
Expand Down

0 comments on commit be6645e

Please sign in to comment.