Я реализовал регрессию logisti c для задачи классификации. Я получаю одно и то же значение для точности, отзыва и F1, равное 1. Что не так?
val model = pipeline.fit(train)
val predicted = model.transform(test)
val predictionAndLabels = predicted.
select($"label",$"prediction").
as[(Double, Double)].
rdd
// Instantiate metrics object
val metrics = new BinaryClassificationMetrics(predictionAndLabels)
// If threshold is 0.5 as what we want, then get the precision and append it to the string. Idea is if score is <0.5 class 0, else class 1.
// Precision by threshold
val precision = metrics.precisionByThreshold
precision.foreach { case (t, p) =>
println(s"Threshold: $t, Precision: $p")
}
// Recall by threshold
val recall = metrics.recallByThreshold
recall.foreach { case (t, r) =>
println(s"Threshold: $t, Recall: $r")
}
// Precision-Recall Curve
val PRC = metrics.pr
// F-measure
val f1Score = metrics.fMeasureByThreshold
f1Score.foreach { case (t, f) =>
println(s"Threshold: $t, F-score: $f, Beta = 1")
}
val beta = 0.5
val fScore = metrics.fMeasureByThreshold(beta)
f1Score.foreach { case (t, f) =>
println(s"Threshold: $t, F-score: $f, Beta = 0.5")
}
// AUPRC
val auPRC = metrics.areaUnderPR
println(s"Area under precision-recall curve = $auPRC")
// Compute thresholds used in ROC and PR curves
val thresholds = precision.map(_._1)
// ROC Curve
val roc = metrics.roc
// AUROC
val auROC = metrics.areaUnderROC
println(s"Area under ROC = $auROC")
val testErr = predictionAndLabels.filter(r => r._1 != r._2).count.toDouble / test.count()
println("Accuracy = " + (1-testErr) * 100 + " %")
Порог: 1.0 , Точность: 1,0 Порог: 0,0, Точность: 0,500809498111171 Порог: 1,0, Напомним: 1,0 Порог: 0,0, Напомним: 1,0
Как правильно рассчитать его?