关于类别顺序可由 labels参数控制调整,例如 labels=[2,1,0],则类别将以这个顺序自上向下排列。默认数字类别是从小到大排列,英文类别是按首字母顺序排列 下面是官方文档上的一个例子 y_true = ["cat", "ant", "cat", "cat", "ant", "bird"] y_pred = ["ant", "ant", "cat", "cat", "ant",...
labels : array-like of shape (n_classes), default=None. List of labels to index the matrix. This may be used to reorder or select a subset of labels. If ``None`` is given, those that appear at least once in ``y_true`` or ``y_pred`` are used in sorted order. sample_weight ...
)4tn, fp, fn, tp = confusion_matrix(y_true, y_pred, labels=[0, 1]).ravel()5print('sensitivity:', tp/(tp+fn))6print('specificity:', tn/(tn+fp))78#if y_true.shape=y_pred.shape=(N, 2)9tn, fp, fn, tp = confusion_matrix(y_true2[:, 0], y_pred2[:, 0], labels=[...
sklearn.metrics.confusion_matrix(y_true,y_pred,*,labels=None,sample_weight=None,normalize=None) 参数解释: y_true: 真实标签值。 y_pred: 通过分类器返回的预测标签。 labels: 索引矩阵的标签列表。 normalize: 接受true/pred/all,表示对真实(行) 、预测(列)条件或所有总体的混淆矩阵进行归一化。默认为N...
sklearn.metrics.confusion_matrix(y_true, y_pred, labels=None, sample_weight=None) 参数 y_true:数组,实例的实际类别序列 y_pred:数组,实例的预测类别序列 labels:需要统计出的类别名称列表。如果为None则在y_true或y_pred中出现过的类别都将排序后作为统计类别 sample_weight:类数组,shape=样本数量,可选的...
labels: 可选参数,表示类别标签。如果不提供,则默认为所有出现在 y_true 和 y_pred 中的唯一标签。 sample_weight: 可选参数,用于每个样本的权重。默认为 None,表示每个样本权重相等。 normalize: 可选参数,指定归一化的方式。默认为 None,表示不进行归一化。如果设置为 'true',则将混淆矩阵的每一行除以相应行...
Code # -*-coding:utf-8-*- from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt import numpy as np #labels表示你不同类别的代号,比如这里的demo中有13个类别 labels = ['A', 'B', 'C', 'F', 'G', 'H ...
7. xtickslabels 和 ytickslabels:这些参数用于指定x轴和y轴的刻度标签。8. show_digit_counts:一个布尔值,决定是否在每个单元格中显示实际数字计数。默认情况下,这是 关闭的(即False)。9. digits:用于指定每个单元格中显示的数字的小数位数。如果没有提供,则默认值为2。以上是plot_confusion_matrix函数的...
2. 了解confusion_matrix函数的基本用法和参数 confusion_matrix函数的基本用途是计算分类模型真实标签与预测标签之间的混淆矩阵。它的主要参数包括: y_true:真实标签的数组。 y_pred:预测标签的数组。 labels:(可选)一个列表,包含要包含在混淆矩阵中的类别标签。如果未提供,则类别标签将自动从y_true和y_pred中推导...