【问题标题】:How to infer the predicted class label from Spark MLlib computed raw score如何从 Spark MLlib 计算的原始分数推断预测的类标签
【发布时间】:2017-04-08 02:36:02
【问题描述】:

阅读下面的 Spark 文档

https://spark.apache.org/docs/latest/mllib-optimization.html

二分类预测示例代码如下:

    val model = new LogisticRegressionModel(
    Vectors.dense(weightsWithIntercept.toArray.slice(0,weightsWithIntercept.size - 1)),
    weightsWithIntercept(weightsWithIntercept.size - 1))

    // Clear the default threshold.
    model.clearThreshold()

   // Compute raw scores on the test set.
   val scoreAndLabels = test.map { point =>
   val score = model.predict(point.features)
   (score, point.label)

如您所见,model.prediction(point.features) 返回原始分数,即到超平面分离距离的边际。

我的问题是:

(1) 根据上面计算的原始分数,我如何知道预测类标签是 0 还是 1?

或者

(2) 如何从上面计算的原始分数中推断出这种二分类情况下的预测类别标签(0,或1)?

【问题讨论】:

    标签: scala apache-spark apache-spark-mllib apache-spark-ml


    【解决方案1】:

    默认情况下,阈值为 0.5,因此在使用BinaryClassificationMetrics 时,如果分数

    【讨论】:

    • 如何得到算法确定计算ROC曲线的最佳阈值?
    • 在metrics对象上,你可以得到各种metrics的阈值分数。例如:val f1Score = metrics.fMeasureByThreshold。然后你可以在这里迭代找到最佳阈值细节:spark.apache.org/docs/latest/mllib-evaluation-metrics.html
    猜你喜欢
    • 2015-10-19
    • 1970-01-01
    • 2017-09-28
    • 2018-04-27
    • 2017-02-02
    • 2018-02-14
    • 2017-10-11
    • 2016-09-10
    相关资源
    最近更新 更多