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_r288139570
##########
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)
+ }.reduceByKey(_ + _)
.collectAsMap()
+
+ private lazy val labelCountByClass: Map[Double, Double] = {
Review comment:
OK yeah I was also thinking you could just compute these all non-lazily, and
do so in one pass over confusions, but, maybe not worth it.
----------------------------------------------------------------
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]