您可以使用sklearn.metrics库中的'classification_report'函数来获取每个类别的分类精度。

示例代码:

from sklearn.metrics import classification_report

# y_true为真实标签,y_pred为预测标签
report = classification_report(y_true, y_pred)
print(report)

输出结果将展示每个类别的精确度、召回率、F1得分等指标。

要绘制混淆矩阵,您可以使用sklearn.metrics库中的'confusion_matrix'函数。

示例代码:

from sklearn.metrics import confusion_matrix
import seaborn as sns

# y_true为真实标签,y_pred为预测标签
cm = confusion_matrix(y_true, y_pred)
sns.heatmap(cm, annot=True, cmap='Blues')

这将绘制一个热力图,其中每个方格表示真实标签为行、预测标签为列的样本数量。注释参数将在每个方格中显示样本数量,'cmap'参数将指定颜色映射。


原文地址: https://www.cveoy.top/t/topic/oYg5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录