0
votes

I'm working on Spark Mllib on Scala for the first time and I'm having trouble instantiating the BinaryClassificationMetrics class. It gives a Cannot resolve constructor error even though I'm formatting its input as an RDD of Tuples as required. Any ideas what might be going wrong?

def modelEvaluation(model: PipelineModel, test: DataFrame): Unit = {
 // Make a prediction on the test set
    val predictionAndLabels = model.transform(test)
      .select("prediction","label")
      .rdd
      .map(r => (r(0),r(1)))
      /*.collect()
      .foreach(r => println(r))*/

    // Instantiate metrics object
    val metrics = new BinaryClassificationMetrics(predictionAndLabels)

    // Precision-Recall Curve
    //val PRC = metrics.pr
  }
1
What is the type of PipelineModel? - sramalingam24

1 Answers

0
votes

BinaryClassificationMetrics need RDD[(Double, Double)], detail: https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.mllib.evaluation.BinaryClassificationMetrics

so you may change like so :

def modelEvaluation(model: PipelineModel, test: DataFrame): Unit = {
  // Make a prediction on the test set
  val predictionAndLabels = model.transform(test)
    .select("prediction","label")
    .rdd
    .map(r => (r(0).toString.toDouble,r(1).toString.toDouble))

  // Instantiate metrics object
  val metrics = new BinaryClassificationMetrics(predictionAndLabels)

  // Precision-Recall Curve
  //val PRC = metrics.pr
}