uchiiii commented on code in PR #36843: URL: https://github.com/apache/spark/pull/36843#discussion_r897422167
########## mllib/src/main/scala/org/apache/spark/mllib/evaluation/RankingMetrics.scala: ########## @@ -142,33 +158,57 @@ class RankingMetrics[T: ClassTag](predictionAndLabels: RDD[(Array[T], Array[T])] @Since("1.2.0") def ndcgAt(k: Int): Double = { require(k > 0, "ranking position k should be positive") - predictionAndLabels.map { case (pred, lab) => - val labSet = lab.toSet - - if (labSet.nonEmpty) { - val labSetSize = labSet.size - val n = math.min(math.max(pred.length, labSetSize), k) - var maxDcg = 0.0 - var dcg = 0.0 - var i = 0 - while (i < n) { - // Base of the log doesn't matter for calculating NDCG, - // if the relevance value is binary. - val gain = 1.0 / math.log(i + 2) - if (i < pred.length && labSet.contains(pred(i))) { - dcg += gain + predictionAndLabels + .map { + case (pred, lab, rel) => + val useBinary = rel.isEmpty + val labSet = lab.toSet + val relMap = (lab zip rel).toMap Review Comment: This is to calculate the `dcg` fast. When `dcg` is calculated, the relevance score of pred(i) is required. (`lab` and `rel` is parallel but pred is not`) FYI: - https://spark.apache.org/docs/1.5.0/mllib-evaluation-metrics.html#ranking-systems - https://github.com/apache/spark/pull/36843/files#diff-5b07c866965423f2ef414592a98e8d22426bd641463d35094bd1ece2656d3657R144 -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org