@@ -45,8 +45,9 @@ class MulticlassMetrics(predictionAndLabels: RDD[(Double, Double)]) {
45
45
(prediction, if (prediction != label) 1 else 0 )
46
46
}.reduceByKey(_ + _)
47
47
.collectAsMap()
48
- private lazy val confusions = predictionAndLabels.map {
49
- case (prediction, label) => ((prediction, label), 1 )
48
+ private lazy val confusions = predictionAndLabels
49
+ .map { case (prediction, label) =>
50
+ ((prediction, label), 1 )
50
51
}.reduceByKey(_ + _).collectAsMap()
51
52
52
53
/**
@@ -55,11 +56,18 @@ class MulticlassMetrics(predictionAndLabels: RDD[(Double, Double)]) {
55
56
* they are ordered by class label ascending,
56
57
* as in "labels"
57
58
*/
58
- lazy val confusionMatrix : Matrix = {
59
+ def confusionMatrix : Matrix = {
59
60
val transposedFlatMatrix = Array .ofDim[Double ](labels.size * labels.size)
60
- for (i <- 0 to labels.size - 1 ; j <- 0 to labels.size - 1 ) {
61
- transposedFlatMatrix(i * labels.size + j)
62
- = confusions.getOrElse((labels(i), labels(j)), 0 ).toDouble
61
+ val n = labels.size
62
+ var i, j = 0
63
+ while (i < n){
64
+ j = 0
65
+ while (j < n){
66
+ transposedFlatMatrix(i * labels.size + j)
67
+ = confusions.getOrElse((labels(i), labels(j)), 0 ).toDouble
68
+ j += 1
69
+ }
70
+ i += 1
63
71
}
64
72
Matrices .dense(labels.size, labels.size, transposedFlatMatrix)
65
73
}
0 commit comments