混淆矩阵生成的标签是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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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