TensorFlow2学习十一之绘制准确率acc和损失函数loss曲线

model.fit中将训练集loss、测试集loss、训练集准确率保存了下来

history=model.fit(训练集数据, 训练集标签, 
	batch_size=, epochs=,
	validation_split=用作测试数据的比例,
	validation_data=测试集, 
	validation_freq=测试频率)

history包含以下几个属性:
训练集loss: loss
测试集loss: val_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']

绘制acc和loss曲线:

plt.subplot(1, 2, 1)
plt.plot(acc, label='Training Accuracy')
plt.plot(val_acc, label='Validation Accuracy')
plt.title('Training and Validation Accuracy')
plt.legend()

plt.subplot(1, 2, 2)
plt.plot(loss, label='Training Loss')
plt.plot(val_loss, label='Validation Loss')
plt.title('Training and Validation Loss')
plt.legend()
plt.show()

你可能感兴趣的:(TensorFlow2.0)