为什么缺少混淆矩阵图的第二行中值?

问题描述 投票:0回答:1
I使用Matplotlib和Seaborn图书馆创建一个令人困惑的矩阵。我根据以下代码构建一个令人困惑的矩阵:

conf_matrix = confusion_matrix(y_test, y_test_predictions) print(conf_matrix) [[122 27] [ 40 42]]
练习,其值全部武装在一个数组中。我现在想使用Matplotlib和Seaborn图书馆使用此信息来绘制这些价值。因此,使用或遵循代码trecho。

plt.figure(figsize=(3, 3), dpi=300) # Scale up the size of all text sns.set(font_scale = 1.1) ax = sns.heatmap(conf_matrix, annot=True, fmt='d', ) # set x-axis label and ticks. ax.set_xlabel("Predicted Diagnosis", fontsize=14, labelpad=20) ax.xaxis.set_ticklabels(['Negative', 'Positive']) # set y-axis label and ticks ax.set_ylabel("Actual Diagnosis", fontsize=14, labelpad=20) ax.yaxis.set_ticklabels(['Negative', 'Positive']) # set plot title ax.set_title("Confusion Matrix for the Diabetes Detection Model", fontsize=14, pad=20) plt.show()

要使用此代码,该代码应该在每个单元格中绘制混乱的矩阵值,数字40和42不会出现(第二个矩阵行)。你有没有别人?
我使用了Jupyter笔记本7.0.8,Python 3.11.7,Matplotlib 3.8.0和Seaborn0.12.2.2.

我在Google Colab上使用Python版本3.11.11运行了您的代码。
python machine-learning evaluation confusion-matrix
1个回答
0
投票
y_test

阵列。

y_predicted

,然后运行提供的代码使用matplotlib绘制了混淆矩阵。
y_test = [0]*122 + [0]*27 + [1]*40 + [1]*42 y_predicted = [0]*122 + [1]*27 + [0]*40 + [1]*42
这里的外观:

灌注矩阵
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.