混乱矩阵随着每次交互而变化



我正在为六个类构建一个混淆矩阵scikit_learn我正在使用混淆矩阵作为绘制矩阵的基本代码。我面临的问题是,每当我重新训练线性 SVM 分类器时,每次训练时混淆矩阵都会发生变化。不。的预测标签保持不变,否。对于每个交互,真正的标签也保持不变。我无法理解为什么混乱矩阵会以这种方式变化。对角线元素也没有任何意义。

请指导我该怎么办。

def plot_confusion_matrix(cm, title='Confusion matrix', cmap=plt.cm.Blues):
    plt.imshow(cm, interpolation='nearest', cmap=cmap)
    plt.title(title)
    plt.colorbar()
    tick_marks = np.arange(6)
    plt.xticks(tick_marks, names, rotation=45)
    plt.yticks(tick_marks, names)
    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label') 
    # this is the main function i am using
    # here names is a list of six titles e.g. names = ['a', 'b', 'c', 'd', 'e', 'f']

#Following is the code that I am using to call the function
cm = confusion_matrix(labels_test, predicted)
np.set_printoptions(precision=2)
print('Confusion matrix, without normalization')
print(cm)
plt.figure()
plot_confusion_matrix(cm)
cm_normalized = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
print('Normalized confusion matrix')
print(cm_normalized)
plt.figure()
plot_confusion_matrix(cm_normalized, title='Normalized confusion matrix')
plt.show()
混淆

矩阵允许您了解分类器在哪些方面做得好(真阳性),哪些地方做得不好(误报)。

混淆矩阵的对角线告诉您特定类被正确分类的次数(真阳性)。

当您

重新训练数据集时,您的分类器似乎会从迭代中更改。因此,真阳性/假阳性/真阴性/假阴性的数量可能不同。

最新更新