【发布时间】: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