history=model.fit(训练集数据, 训练集标签, batch_size=, epochs=,
validation_split=用作测试数据的比例,validation_data=测试集, validation_freq=测试频率)
history:
loss:训练集loss
val_loss:测试集loss
sparse_categorical_accuracy:训练集准确率
val_sparse_categorical_accuracy:测试集准确率
acc = history.history['sparse_categorical_accuracy']
val_acc = history.history['val_sparse_categorical_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
print(acc)
print(val_acc)
print(loss)
print(val_loss)
# [0.9254000186920166, 0.9668499827384949, 0.9761666655540466, 0.9825999736785889, 0.9862499833106995]
# [0.9592999815940857, 0.9706000089645386, 0.9775000214576721, 0.9761999845504761, 0.9765999913215637]
# [0.26014444231987, 0.113783098757267, 0.07880879193544388, 0.0564233660697937, 0.0446171797811985]
# [0.1373901069164276, 0.09307443350553513, 0.0812087282538414, 0.08124100416898727, 0.07900043576955795]
fig = plt.figure(figsize=(10,10))
ax=fig.add_subplot(1,2,1)
ax.plot(acc,label="TA")
ax.plot(val_acc,label="VTA")
ax.set_title("Training And Validation Accuracy")
plt.legend()
ax=fig.add_subplot(1,2,2)
ax.plot(loss,label="TL")
ax.plot(val_loss,label="VTL")
ax.set_title("Training And Validation Loss")
plt.legend()
plt.show()
测试结果: