一:在训练好的模型下面加入绘图代码。
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
history = model.fit(X_train, Y_train, epochs=200, batch_size=10, verbose=2, validation_split=0.33)
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(len(acc))
plt.plot(epochs,acc, 'b', label='Training accuracy')
plt.plot(epochs, val_acc, 'r', label='validation accuracy')
plt.title('Training and validation accuracy')
plt.legend(loc='lower right')
plt.figure()
plt.plot(epochs, loss, 'r', label='Training loss')
plt.plot(epochs, val_loss, 'b', label='validation loss')
plt.title('Training and validation loss')
plt.legend()
plt.show()
'b’代表绿色,'r’代表红色,用’bo’可以把线段换成圆点。
plt.legend()默认找一个空白的地方写标签。
plt.legend(loc=‘lower right’)指定标签在右下角,也可以指定位置为右上,左上,左下。