一、打印分类报告(使用scikit-learn库中的函数)
from sklearn.metrics import classification_report
# y_test为测试集真实标签, y_pred为测试集预测的标签
print(classification_report(y_test, y_pred))
例子:
# Standard scientific Python imports
import matplotlib.pyplot as plt
# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
from sklearn.model_selection import train_test_split
# The digit dataset
digits = datasets.load_digits()
"""
The data that we are interested in is made of 8x8 images of digits, Let's
have a look at the first 4 images, stored in the 'images' attributes of the
dataset. If we were working from image files, we could load them using
'matplotlib.pyplot.imread'. Note that each image must have the same size.
For these images, we know which digit they represent: it is given in the 'target' of the dataset.
"""
_, axes = plt.subplots(2, 4)
images_and_labels = list(zip(digits.images, digits.target))
for ax, (image, label

本文介绍了如何使用scikit-learn库打印分类报告,包括准确率、精确率、召回率和F1值等关键指标。通过示例代码展示了如何获取这些评估指标,并提供了相关参考资料链接。
最低0.47元/天 解锁文章
1073

被折叠的 条评论
为什么被折叠?



