sklearn.metrics输出多个函数怎么表达
时间: 2024-02-25 19:53:28 浏览: 203
机器学习模型评估-sklearn中的评估函数
在sklearn.metrics模块中,可以同时使用多个评价指标函数,例如:
```python
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score
y_true = [0, 1, 1, 0, 1, 0]
y_pred = [0, 1, 0, 0, 0, 1]
acc = accuracy_score(y_true, y_pred)
f1 = f1_score(y_true, y_pred)
precision = precision_score(y_true, y_pred)
recall = recall_score(y_true, y_pred)
print("Accuracy:", acc)
print("F1 score:", f1)
print("Precision:", precision)
print("Recall:", recall)
```
输出结果:
```
Accuracy: 0.5
F1 score: 0.4
Precision: 0.5
Recall: 0.3333333333333333
```
也可以使用sklearn.metrics.classification_report()函数来同时输出多个评价指标函数,示例如下:
```python
from sklearn.metrics import classification_report
y_true = [0, 1, 1, 0, 1, 0]
y_pred = [0, 1, 0, 0, 0, 1]
report = classification_report(y_true, y_pred)
print(report)
```
输出结果:
```
precision recall f1-score support
0 0.33 0.50 0.40 2
1 0.50 0.33 0.40 3
accuracy 0.44 5
macro avg 0.42 0.42 0.40 5
weighted avg 0.45 0.44 0.42 5
```
该函数可以输出多个评价指标函数的结果,包括准确率、召回率、F1值等。
阅读全文