我已经为分类问题实现了逻辑回归。我在精度、召回率和 F1 分数方面得到了相同的值。是否可以具有相同的值?我在实现决策树和随机森林时也遇到了这个问题。在精度、召回率和 F1 分数方面,我也得到了相同的值。
// Run training algorithm to build the model.
final LogisticRegressionModel model = new LogisticRegressionWithLBFGS()
.setNumClasses(13).
run(data.rdd());
//Compute raw scores on the test set.
JavaRDD<Tuple2<Object, Object>> predictionAndLabels = testData.map(
new Function<LabeledPoint, Tuple2<Object, Object>>() {
public Tuple2<Object, Object> call(LabeledPoint p) {
Double prediction = model.predict(p.features());
return new Tuple2<Object, Object>(prediction, p.label());
}
}
);
// Get evaluation metrics.
MulticlassMetrics metrics = new MulticlassMetrics(predictionAndLabels.rdd());
double precision = metrics.precision();
System.out.println("Precision = " + precision);
double recall = metrics.recall();
System.out.println("Recall = " + recall);
double FScore = metrics.fMeasure();
System.out.println("F Measure = " + FScore);