import org.apache.spark.mllib.classification.LogisticRegressionWithLBFGS
import org.apache.spark.mllib.evaluation.MulticlassMetrics
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.util.MLUtils
val predictionAndLabels = test.map { case LabeledPoint(label,
features) =>
val prediction = model.predict(features)
(prediction, label)
}
val metrics = new MulticlassMetrics(predictionAndLabels)
Матрица путаницы
println("Confusion matrix:")
println(metrics.confusionMatrix)
Общая статистика
val accuracy = metrics.accuracy
println("Summary Statistics")
println(s"Accuracy = $accuracy")
Точность по метке
val labels = metrics.labels
labels.foreach { l =>
println(s"Precision($l) = " + metrics.precision(l))
}
Отзыв по метке
labels.foreach { l =>
println(s"Recall($l) = " + metrics.recall(l))
}
Неверно положительный показатель по метке
labels.foreach { l =>
println(s"FPR($l) = " + metrics.falsePositiveRate(l))
}
F-мера по метке
labels.foreach { l =>
println(s"F1-Score($l) = " + metrics.fMeasure(l))
}
Взвешенная статистика
println(s"Weighted precision: ${metrics.weightedPrecision}")
println(s"Weighted recall: ${metrics.weightedRecall}")
println(s"Weighted F1 score: ${metrics.weightedFMeasure}")
println(s"Weighted false positive rate: ${metrics.weightedFalsePositiveRate}")