我想看看准确率和召回率如何随阈值变化(而不仅仅是相互之间)
model = RandomForestClassifier(500, n_jobs = -1);
model.fit(X_train, y_train);
probas = model.predict_proba(X_test)[:, 1]
precision, recall, thresholds = precision_recall_curve(y_test, probas)
print len(precision)
print len(thresholds)
返回:
283
282
因此,我不能将它们绘制在一起。关于为什么会这样的任何线索?
最佳答案
对于这个问题,应该忽略最后的precision和recall值 最后的精度和召回值总是分别为 1 和 0,并且没有相应的阈值。
例如这里有一个解决方案:
def plot_precision_recall_vs_threshold(precisions, recall, thresholds):
fig = plt.figure(figsize= (8,5))
plt.plot(thresholds, precisions[:-1], "b--", label="Precision")
plt.plot(thresholds, recall[:-1], "g-", label="Recall")
plt.legend()
plot_precision_recall_vs_threshold(precision, recall, thresholds)
这些值应该存在,以便在绘制精度与召回率时,绘图从 y 轴 (x=0) 开始。
关于python - 在 scikit 的 precision_recall_curve 中,为什么阈值与召回率和精度具有不同的维度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31639016/