srowen commented on a change in pull request #24458: [SPARK-27540][MLlib] Add
'meanAveragePrecision_at_k' metric to RankingMetrics
URL: https://github.com/apache/spark/pull/24458#discussion_r278597425
##########
File path:
mllib/src/main/scala/org/apache/spark/mllib/evaluation/RankingMetrics.scala
##########
@@ -92,6 +92,56 @@ class RankingMetrics[T: ClassTag](predictionAndLabels:
RDD[(Array[T], Array[T])]
}.mean()
}
+ /**
+ * Returns the mean average precision (MAP) at ranking position k of all the
queries.
+ * If a query has an empty ground truth set, the average precision will be
zero and a log
+ * warning is generated.
+ * @param k the position to compute the truncated precision, must be positive
+ * @return the mean average precision at first k ranking positions
+ */
+ @Since("3.0.0")
+ def meanAveragePrecisionAt(k: Int): Double = {
+ require(k > 0, "ranking position k should be positive")
+ predictionAndLabels
Review comment:
Nit: I would put this all onto 1-2 lines.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]