srowen commented on a change in pull request #24717: [SPARK-27847][ML] One-Pass
MultilabelMetrics & MulticlassMetrics
URL: https://github.com/apache/spark/pull/24717#discussion_r288137476
##########
File path:
mllib/src/main/scala/org/apache/spark/mllib/evaluation/MulticlassMetrics.scala
##########
@@ -55,31 +48,59 @@ class MulticlassMetrics @Since("1.1.0")
(predictionAndLabels: RDD[_ <: Product])
throw new IllegalArgumentException(s"Expected Row of tuples, got
$other")
})
- private lazy val labelCountByClass: Map[Double, Double] =
- predLabelsWeight.map {
- case (_: Double, label: Double, weight: Double) =>
- (label, weight)
- }.reduceByKey(_ + _)
+
+ private val confusions = predictionAndLabels.map {
+ case (prediction: Double, label: Double, weight: Double) =>
+ (prediction, label, weight)
+ case (prediction: Double, label: Double) =>
+ (prediction, label, 1.0)
+ case other =>
+ throw new IllegalArgumentException(s"Expected tuples, got $other")
+ }.map { case (prediction: Double, label: Double, weight: Double) =>
+ ((label, prediction), weight)
Review comment:
Rather than map twice, can you just combine (prediction, label) in the cases
above?
----------------------------------------------------------------
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]