scikit-learn:打印分类报告,求准确率、精确率、召回率、F1值等指标

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、打印分类报告(使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值