正确率召回率ROC曲线python代码
时间: 2023-11-13 11:55:14 浏览: 42
好的,以下是正确率召回率ROC曲线的Python代码:
```python
import matplotlib.pyplot as plt
from sklearn.metrics import precision_recall_curve, roc_curve, auc
# 假设y_true和y_score是我们的真实标签和预测概率
precision, recall, thresholds = precision_recall_curve(y_true, y_score)
fpr, tpr, thresholds = roc_curve(y_true, y_score)
# 计算AUC值
roc_auc = auc(fpr, tpr)
# 绘制ROC曲线
plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic')
plt.legend(loc="lower right")
plt.show()
# 绘制正确率召回率曲线
plt.step(recall, precision, color='b', alpha=0.2, where='post')
plt.fill_between(recall, precision, step='post', alpha=0.2, color='b')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.ylim([0.0, 1.05])
plt.xlim([0.0, 1.0])
plt.title('Precision-Recall curve: AP={0:0.2f}'.format(average_precision))
plt.show()
```
其中,`y_true`是真实标签,`y_score`是预测概率。