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运行了您的代码。
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
这里的外观:
灌注矩阵