混淆矩阵生成的标签是a和b,而不是我需要的

我有一个分类箱,我的标签应该是’points’,但是在生成混淆矩阵时,它生成的标签是a和b,而不是我期望的’90分以上’和’90分以下’。这是我的代码。

print(y_test.values)cm = confusion_matrix(y_test.values, preds)def plot_confusion_matrix(cm, classes,                      normalize=False,                      title='Confusion matrix',                      cmap=plt.cm.Blues):"""This function prints and plots the confusion matrix.Normalization can be applied by setting `normalize=True`."""if normalize:    cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]    print("Normalized confusion matrix")else:    print('Confusion matrix, without normalization')print(cm)plt.imshow(cm, interpolation='nearest', cmap=cmap)plt.title(title)plt.colorbar()tick_marks = np.arange(len(classes))plt.xticks(tick_marks, classes, rotation=45)plt.yticks(tick_marks, classes)fmt = '.2f' if normalize else 'd'thresh = cm.max() / 2.for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):    plt.text(j, i, format(cm[i, j], fmt),             horizontalalignment="center",             color="white" if cm[i, j] > thresh else "black")plt.tight_layout()plt.ylabel('True label')plt.xlabel('Predicted label')plt.figure()plot_confusion_matrix(cm)plt.show()

这是我的图表,显示的是a和b,而不是’90分以下’和’90分以上’enter image description here


回答:

在研究模型的过程中,我观察到了一些我认为是解决这个问题的更好方法。也许有人会觉得这有帮助,所以我想澄清这个问题。

我从一个标签创建了一个分类箱,所以标签是points,我创建的分类箱是’90分以上’和’90分以下’,所以这些应该是图表的标签,而不是‘a’和’b’。在上面的例子中,我在创建分类箱时很好地平衡了数据。

因此,我修改了我的代码,以便得到如下的混淆矩阵图

 plt.tight_layout() plt.ylabel('True label') plt.xlabel('Predicted label') plt.figure() plot_confusion_matrix(cm,['points above 90', 'points below 90'])

enter image description here

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注