用将预测结果可视化
代码:
测试集输出结果可视化
import matplotlib.pyplot as plt
%matplotlib inline
def res_Visual(n):
final_opt_a=new_model.predict_classes(X_test[0:n])# 通过模型预测测试集
fig, ax = plt.subplots(nrows=int(n/5),ncols=5 )
ax = ax.flatten()
print('前{}张图片预测结果为:'.format(n))
for i in range(n):
print(final_opt_a[i],end=',')
if int((i+1)%5) ==0:
print('\t')
#图片可视化展示
img = X_test[i].reshape((28,28))#读取每行数据,格式为Ndarry
plt.axis("off")
ax[i].imshow(img, cmap='Greys', interpolation='nearest')#可视化
ax[i].axis("off")
print('测试集前{}张图片为:'.format(n))
res_Visual(20)
输出:
前20张图片预测结果为:
7,2,1,0,4,
1,4,9,5,9,
0,6,9,0,1,
5,9,7,3,4,