我的环境是:
date........................ 2019-11-10
Operating system version.... Windows-10-10.0.18362-SP0
Python version is........... 3.7.3
scikit-learn version is..... 0.21.3
pandas version is........... 0.25.2
numpy version is............ 1.16.5
matplotlib version is....... 3.1.1
我正在尝试使用以下代码绘制混淆矩阵:
plt.clf()
plt.figure(figsize=(10, 7), clear=True)
cmap = plt.cm.Blues
plt.imshow(cm_test, interpolation='nearest', cmap=cmap)
title = 'Confusion matrix (on test data)'
classes = [1, 0]
plt.title(title)
tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation=0)
plt.yticks(tick_marks, classes)
thresh = cm_test.max() / 2.
for i, j in itertools.product(range(cm_test.shape[0]), range(cm_test.shape[1])):
plt.text(j, i, cm_test[i, j],
horizontalalignment='center',
verticalalignment='center',
color="white" if cm_test[i, j] > thresh else "black")
plt.ylabel('Actual Altitude')
plt.xlabel('Predicted Altitude')
plt.show()
上面的代码产生以下图:
我的问题是:“为什么文本标签不在框中居中?
任何帮助将不胜感激。
查尔斯