【发布时间】:2016-04-09 22:18:41
【问题描述】:
在使用它进行评分之前,我将逻辑回归的阈值设置为 0.5。我现在想获得该值的精度、召回率和 f1 分数。不幸的是,当我尝试这样做时,我看到的唯一阈值是 1.0 和 0.0。如何获取 0 和 1 以外的阈值指标。
例如这里是 o/p:
阈值为:1.0,精度为:0.85
阈值为:0.0,精度为:0.312641
我没有得到阈值 0.5 的精度。这是相关代码。
// 我在这里设置我的逻辑回归模型的阈值。
model.setThreshold(0.5)
// Compute the score and generate an RDD with prediction and label values.
val predictionAndLabels = data.map {
case LabeledPoint(label, features) => (model.predict(features), label)
}
// 我现在要计算准确率和召回率等指标。由于我已将模型阈值设置为 0.5,因此我希望获得该值的 PR。
val metrics = new BinaryClassificationMetrics(predictionAndLabels)
val precision = metrics.precisionByThreshold()
precision.foreach {
case (t, p) => {
println(s"Threshold is: $t, Precision is: $p")
if (t == 0.5) {
println(s"Desired: Threshold is: $t, Precision is: $p")
}
}
【问题讨论】:
-
我刚刚在这里回答了一个类似的问题stackoverflow.com/questions/34216481/…
标签: scala apache-spark apache-spark-mllib