Skip to content
Snippets Groups Projects
Commit 381cb161 authored by Yanbo Liang's avatar Yanbo Liang Committed by Xiangrui Meng
Browse files

[SPARK-8068] [MLLIB] Add confusionMatrix method at class MulticlassMetrics in pyspark/mllib

Add confusionMatrix method at class MulticlassMetrics in pyspark/mllib

Author: Yanbo Liang <ybliang8@gmail.com>

Closes #7286 from yanboliang/spark-8068 and squashes the following commits:

6109fe1 [Yanbo Liang] Add confusionMatrix method at class MulticlassMetrics in pyspark/mllib
parent 4ffc27ca
No related branches found
No related tags found
No related merge requests found
......@@ -152,6 +152,10 @@ class MulticlassMetrics(JavaModelWrapper):
>>> predictionAndLabels = sc.parallelize([(0.0, 0.0), (0.0, 1.0), (0.0, 0.0),
... (1.0, 0.0), (1.0, 1.0), (1.0, 1.0), (1.0, 1.0), (2.0, 2.0), (2.0, 0.0)])
>>> metrics = MulticlassMetrics(predictionAndLabels)
>>> metrics.confusionMatrix().toArray()
array([[ 2., 1., 1.],
[ 1., 3., 0.],
[ 0., 0., 1.]])
>>> metrics.falsePositiveRate(0.0)
0.2...
>>> metrics.precision(1.0)
......@@ -186,6 +190,13 @@ class MulticlassMetrics(JavaModelWrapper):
java_model = java_class(df._jdf)
super(MulticlassMetrics, self).__init__(java_model)
def confusionMatrix(self):
"""
Returns confusion matrix: predicted classes are in columns,
they are ordered by class label ascending, as in "labels".
"""
return self.call("confusionMatrix")
def truePositiveRate(self, label):
"""
Returns true positive rate for a given label (category).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment