【发布时间】:2020-09-10 19:22:54
【问题描述】:
我写了一个函数来查找我的模型的混淆矩阵:
NN_model = KNeighborsClassifier(n_neighbors=1)
NN_model.fit(mini_train_data, mini_train_labels)
# Create the confusion matrix for the dev data
confusion = confusion_matrix(dev_labels, NN_model.predict(dev_data))
print(confusion)
但我无法显示经常与其他数字混淆的超过 5 位数字的图像。但是当我尝试下面的代码时,我没有得到预期的结果。
index = 0
misclassifiedIndexes = []
for label, predict in zip(dev_labels, predictions):
if label != predict:
misclassifiedIndexes.append(index)
index +=1
plt.figure(figsize=(20,4))
for plotIndex, badIndex in enumerate(misclassifiedIndexes[0:5]):
plt.subplot(1, 5, plotIndex + 1)
plt.imshow(np.reshape(dev_data[badIndex], (28,28)), cmap=plt.cm.gray)
plt.title('Predict: {}, Actual: {}'.format(predictions[badIndex], dev_labels[badIndex]), fontsize = 15)
您能看看我的代码出了什么问题吗?谢谢!
【问题讨论】: