You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/03/04 08:46:59 UTC

[GitHub] [spark] masa3141 commented on a change in pull request #23881: [SPARK-26981][MLlib] Add 'Recall_at_k' metric to RankingMetrics

masa3141 commented on a change in pull request #23881: [SPARK-26981][MLlib] Add 'Recall_at_k' metric to RankingMetrics
URL: https://github.com/apache/spark/pull/23881#discussion_r261963440
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/mllib/evaluation/RankingMetrics.scala
 ##########
 @@ -157,6 +157,46 @@ class RankingMetrics[T: ClassTag](predictionAndLabels: RDD[(Array[T], Array[T])]
     }.mean()
   }
 
+  /**
+    * Compute the average recall of all the queries, truncated at ranking position k.
+    *
+    * If for a query, the ranking algorithm returns n results, the recall value will be
+    * computed as #(relevant items retrieved) / #(ground truth set). 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, zero will be used as recall together with
+    * a log warning.
+    *
+    * See the following paper for detail:
+    *
+    * IR evaluation methods for retrieving highly relevant documents. K. Jarvelin and J. Kekalainen
+    *
+    * @param k the position to compute the truncated recall, must be positive
+    * @return the average recall at the first k ranking positions
+    */
+  @Since("2.5.0")
+  def recallAt(k: Int): Double = {
+    require(k > 0, "ranking position k should be positive")
+    predictionAndLabels.map { case (pred, lab) =>
 
 Review comment:
   Thanks, I refactored the code.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org