一、打印分类报告(使用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