我对BinaryClassificationMetrics(Mllib)输入感到困惑.根据
Apache Spark 1.6.0,我们需要从已经预测的变换的DataFrame中传递类型的预测和标签(RDD [(Double,Double)]),概率(向量)& rawPrediction(向量).
我已经从Predicted和label列创建了RDD [(Double,Double)].在NavieBayesModel上执行BinaryClassificationMetrics评估后,我能够检索ROC,PR等.但是值有限,我无法使用从中生成的值绘制曲线. Roc包含4个值,PR包含3个值.
它是准备PredictedandLabel的正确方法还是我需要使用rawPrediction列或Probability列而不是Predicted列?
解决方法
准备这样:
import org.apache.spark.mllib.linalg.Vector import org.apache.spark.mllib.classification.{NaiveBayes,NaiveBayesModel} val df = sqlContext.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt") val predictions = new NaiveBayes().fit(df).transform(df) val preds = predictions.select("probability","label").rdd.map(row => (row.getAs[Vector](0)(0),row.getAs[Double](1)))
并评估:
import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics new BinaryClassificationMetrics(preds,10).roc
如果预测只有0或1个桶可以像你的情况一样更低.尝试更复杂的数据,如下所示:
val anotherPreds = df1.select(rand(),$"label").rdd.map(row => (row.getDouble(0),row.getDouble(1))) new BinaryClassificationMetrics(anotherPreds,10).roc