Spark ML - MulticlassClassificationEvaluator - can we get precision/recall by each class label?
Asked Answered
W

2

12

I am doing a multiclass prediction with random forest in Spark ML.

For this MulticlassClassificationEvaluator() in spark ML, is it possible to get precision/recall by each class labels?

Currently, I am only seeing precision/recall combined for all class together.

Wrought answered 27/12, 2016 at 20:20 Comment(1)
Precision/ recall is also removed from lastest version of spark [2.3.0]Staircase
M
1

Use directly org.apache.spark.mllib.evaluation.MulticlassMetrics and then get metrics available-

// copied from spark git
val predictionAndLabels =
      dataset.select(col($(predictionCol)), col($(labelCol)).cast(DoubleType)).rdd.map {
        case Row(prediction: Double, label: Double) => (prediction, label)
      }
    val metrics = new MulticlassMetrics(predictionAndLabels)
Mulligan answered 24/5, 2020 at 7:4 Comment(0)
F
0

Looking at the class documentation this doesn't seem to be possible, using the built-in methods.

Although not exactly what you are looking for, you could use weightedPrecisionand weightedRecall in the metricName method. This will at least account for class imbalances.

Fenwick answered 2/8, 2018 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.