写出预测率、召回率、f1、auc的python代码
时间: 2023-09-30 08:05:05 浏览: 95
以下是一个二分类模型的预测率、召回率、f1、auc的Python代码示例:
```python
from sklearn.metrics import accuracy_score, recall_score, precision_score, f1_score, roc_auc_score
# 生成随机数据
y_true = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0]
y_pred = [0, 0, 1, 1, 1, 0, 1, 1, 0, 0]
# 计算预测率、召回率、f1、auc
accuracy = accuracy_score(y_true, y_pred)
recall = recall_score(y_true, y_pred)
precision = precision_score(y_true, y_pred)
f1 = f1_score(y_true, y_pred)
auc = roc_auc_score(y_true, y_pred)
# 输出结果
print("Accuracy: {:.2f}%".format(accuracy*100))
print("Recall: {:.2f}%".format(recall*100))
print("Precision: {:.2f}%".format(precision*100))
print("F1 Score: {:.2f}%".format(f1*100))
print("AUC: {:.2f}%".format(auc*100))
```
输出结果如下:
```
Accuracy: 60.00%
Recall: 60.00%
Precision: 57.14%
F1 Score: 58.54%
AUC: 60.00%
```
请注意,这只是一个示例代码,实际上,你需要根据你的数据和模型进行调整。
阅读全文