matplotlib
plt.figure() 定义一个图像窗口 plt.figure(num=3, figsize=(8, 5),) 编号为3,大小为(8, 5)
plt.plot(x, y) plt.plot画(x ,y)曲线 , plt.plot(x, y1, color=‘red’, linewidth=1.0, linestyle=’–’)
plt.show() plt.show显示图像.
keras history object
# define the function
def training_vis(hist):
loss = hist.history['loss']
val_loss = hist.history['val_loss']
acc = hist.history['acc']
val_acc = hist.history['val_acc']
# make a figure
fig = plt.figure(figsize=(8,4))
# subplot loss
ax1 = fig.add_subplot(121)
ax1.plot(loss,label='train_loss')
ax1.plot(val_loss,label='val_loss')
ax1.set_xlabel('Epochs')
ax1.set_ylabel('Loss')
ax1.set_title('Loss on Training and Validation Data')
ax1.legend()
# subplot acc
ax2 = fig.add_subplot(122)
ax2.plot(acc,label='train_acc')
ax2.plot(val_acc,label='val_acc')
ax2.set_xlabel('Epochs')
ax2.set_ylabel('Accuracy')
ax2.set_title('Accuracy on Training and Validation Data')
ax2.legend()
plt.tight_layout()
hist = model.fit(...)
training_vis(hist)