admin管理员组文章数量:1310143
I build a confusion matrix according to the code below:
conf_matrix = confusion_matrix(y_test, y_test_predictions)
print(conf_matrix)
[[122 27]
[ 40 42]]
Observe that the values for it are all armed in an array. I want to plot these values right now with this information using matplotlib and the seaborn library. For this reason, use or follow the code 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()
To use this code, which should plot the confusing matrix values in each cell, numbers 40 and 42 will not appear (second matrix line). Have you ever passed by someone else?
I'm used the jupyter notebook 7.0.8, python 3.11.7, matplotlib 3.8.0 and seaborn 0.12.2.
I build a confusion matrix according to the code below:
conf_matrix = confusion_matrix(y_test, y_test_predictions)
print(conf_matrix)
[[122 27]
[ 40 42]]
Observe that the values for it are all armed in an array. I want to plot these values right now with this information using matplotlib and the seaborn library. For this reason, use or follow the code 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()
To use this code, which should plot the confusing matrix values in each cell, numbers 40 and 42 will not appear (second matrix line). Have you ever passed by someone else?
I'm used the jupyter notebook 7.0.8, python 3.11.7, matplotlib 3.8.0 and seaborn 0.12.2.
Share Improve this question edited Feb 3 at 10:35 desertnaut 60.4k32 gold badges152 silver badges180 bronze badges asked Feb 2 at 11:45 Edvonaldo HoracioEdvonaldo Horacio 111 bronze badge1 Answer
Reset to default 0I ran your code on Google Colab with Python version 3.11.11 and it worked perfectly.
I made dummy y_test
and y_predicted
arrays.
y_test = [0]*122 + [0]*27 + [1]*40 + [1]*42
y_predicted = [0]*122 + [1]*27 + [0]*40 + [1]*42
Then, running your provided code plotted the confusion matrix using matplotlib.
conf_matrix = confusion_matrix(y_test, y_predicted)
print(conf_matrix)
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()
Here's how it looked: Confusion Matrix
本文标签: pythonWhy values in the second row of the confusion matrix plot are missingStack Overflow
版权声明:本文标题:python - Why values in the second row of the confusion matrix plot are missing? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741849415a2400974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论