pyspark.mllib.evaluation.
MulticlassMetrics
Evaluator for multiclass classification.
New in version 1.4.0.
pyspark.RDD
an RDD of prediction, label, optional weight and optional probability.
Examples
>>> 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) 0.75... >>> metrics.recall(2.0) 1.0... >>> metrics.fMeasure(0.0, 2.0) 0.52... >>> metrics.accuracy 0.66... >>> metrics.weightedFalsePositiveRate 0.19... >>> metrics.weightedPrecision 0.68... >>> metrics.weightedRecall 0.66... >>> metrics.weightedFMeasure() 0.66... >>> metrics.weightedFMeasure(2.0) 0.65... >>> predAndLabelsWithOptWeight = sc.parallelize([(0.0, 0.0, 1.0), (0.0, 1.0, 1.0), ... (0.0, 0.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 1.0), (1.0, 1.0, 1.0), (1.0, 1.0, 1.0), ... (2.0, 2.0, 1.0), (2.0, 0.0, 1.0)]) >>> metrics = MulticlassMetrics(predAndLabelsWithOptWeight) >>> metrics.confusionMatrix().toArray() array([[ 2., 1., 1.], [ 1., 3., 0.], [ 0., 0., 1.]]) >>> metrics.falsePositiveRate(0.0) 0.2... >>> metrics.precision(1.0) 0.75... >>> metrics.recall(2.0) 1.0... >>> metrics.fMeasure(0.0, 2.0) 0.52... >>> metrics.accuracy 0.66... >>> metrics.weightedFalsePositiveRate 0.19... >>> metrics.weightedPrecision 0.68... >>> metrics.weightedRecall 0.66... >>> metrics.weightedFMeasure() 0.66... >>> metrics.weightedFMeasure(2.0) 0.65... >>> predictionAndLabelsWithProbabilities = sc.parallelize([ ... (1.0, 1.0, 1.0, [0.1, 0.8, 0.1]), (0.0, 2.0, 1.0, [0.9, 0.05, 0.05]), ... (0.0, 0.0, 1.0, [0.8, 0.2, 0.0]), (1.0, 1.0, 1.0, [0.3, 0.65, 0.05])]) >>> metrics = MulticlassMetrics(predictionAndLabelsWithProbabilities) >>> metrics.logLoss() 0.9682...
Methods
call(name, *a)
call
Call method of java_model
confusionMatrix()
confusionMatrix
Returns confusion matrix: predicted classes are in columns, they are ordered by class label ascending, as in “labels”.
fMeasure(label[, beta])
fMeasure
Returns f-measure.
falsePositiveRate(label)
falsePositiveRate
Returns false positive rate for a given label (category).
logLoss([eps])
logLoss
Returns weighted logLoss.
precision(label)
precision
Returns precision.
recall(label)
recall
Returns recall.
truePositiveRate(label)
truePositiveRate
Returns true positive rate for a given label (category).
weightedFMeasure([beta])
weightedFMeasure
Returns weighted averaged f-measure.
Attributes
accuracy
Returns accuracy (equals to the total number of correctly classified instances out of the total number of instances).
weightedFalsePositiveRate
Returns weighted false positive rate.
weightedPrecision
Returns weighted averaged precision.
weightedRecall
Returns weighted averaged recall.
weightedTruePositiveRate
Returns weighted true positive rate.
Methods Documentation
New in version 3.0.0.
Attributes Documentation
New in version 2.0.0.
Returns weighted averaged recall. (equals to precision, recall and f-measure)
Returns weighted true positive rate. (equals to precision, recall and f-measure)