温馨提示×

Scikit-learn中怎么实现模型评估报告

小亿
87
2024-05-10 18:43:00
栏目: 编程语言

在Scikit-learn中,可以使用classification_report函数来生成模型评估报告。这个函数可以输出精确度、召回率、F1值以及支持度等指标。

下面是一个示例代码,展示如何使用classification_report函数来生成模型评估报告:

from sklearn.metrics import classification_report

# 假设y_true是真实标签,y_pred是模型的预测结果
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 1, 1, 2, 1]

# 输出模型评估报告
print(classification_report(y_true, y_pred))

运行以上代码,会输出如下的模型评估报告:

              precision    recall  f1-score   support

           0       1.00      1.00      1.00         1
           1       0.50      1.00      0.67         1
           2       1.00      0.67      0.80         3

    accuracy                           0.80         5
   macro avg       0.83      0.89      0.82         5
weighted avg       0.90      0.80      0.82         5

在这个报告中,每个类别(0, 1, 2)都有自己的精确度、召回率、F1值和支持度等指标。同时,还会给出整体的精确度、召回率、F1值和支持度等指标。

0