Skip to content

Commit 2eae80f

Browse files
committed
Merge pull request #1 from mengxr/avulanov-master
minor updates
2 parents 79c3555 + 5ebeb08 commit 2eae80f

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

mllib/src/main/scala/org/apache/spark/mllib/evaluation/MulticlassMetrics.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ class MulticlassMetrics(predictionAndLabels: RDD[(Double, Double)]) {
4747
.collectAsMap()
4848
private lazy val confusions = predictionAndLabels
4949
.map { case (prediction, label) =>
50-
((prediction, label), 1)
51-
}.reduceByKey(_ + _).collectAsMap()
50+
((label, prediction), 1)
51+
}.reduceByKey(_ + _)
52+
.collectAsMap()
5253

5354
/**
5455
* Returns confusion matrix:
@@ -57,19 +58,18 @@ class MulticlassMetrics(predictionAndLabels: RDD[(Double, Double)]) {
5758
* as in "labels"
5859
*/
5960
def confusionMatrix: Matrix = {
60-
val transposedFlatMatrix = Array.ofDim[Double](labels.size * labels.size)
6161
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
62+
val values = Array.ofDim[Double](n * n)
63+
var i = 0
64+
while (i < n) {
65+
var j = 0
66+
while (j < n) {
67+
values(i + j * n) = confusions.getOrElse((labels(i), labels(j)), 0).toDouble
6868
j += 1
6969
}
7070
i += 1
7171
}
72-
Matrices.dense(labels.size, labels.size, transposedFlatMatrix)
72+
Matrices.dense(n, n, values)
7373
}
7474

7575
/**

mllib/src/test/scala/org/apache/spark/mllib/evaluation/MulticlassMetricsSuite.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
package org.apache.spark.mllib.evaluation
1919

20+
import org.scalatest.FunSuite
21+
2022
import org.apache.spark.mllib.linalg.Matrices
2123
import org.apache.spark.mllib.util.LocalSparkContext
22-
import org.scalatest.FunSuite
2324

2425
class MulticlassMetricsSuite extends FunSuite with LocalSparkContext {
2526
test("Multiclass evaluation metrics") {

0 commit comments

Comments
 (0)