根据模型训练结果绘制准确率和损失值曲线图


 1  1 history = model.fit()
 2  2 
 3  3 def plot_acc_loss_curve(history):
 4  4     # 显示训练集和验证集的acc和loss曲线
 5  5     from matplotlib import pyplot as plt
 6  6     acc = history.history['sparse_categorical_accuracy']
 7  7     val_acc = history.history['val_sparse_categorical_accuracy']
 8  8     loss = history.history['loss']
 9  9     val_loss = history.history['val_loss']
10 10     
11 11     plt.figure(figsize=(15, 5))
12 12     plt.subplot(1, 2, 1)
13 13     plt.plot(acc, label='Training Accuracy')
14 14     plt.plot(val_acc, label='Validation Accuracy')
15 15     plt.title('Training and Validation Accuracy')
16 16     plt.legend()
17 17     #plt.grid()
18 18     
19 19     plt.subplot(1, 2, 2)
20 20     plt.plot(loss, label='Training Loss')
21 21     plt.plot(val_loss, label='Validation Loss')
22 22     plt.title('Training and Validation Loss')
23 23     plt.legend()
24 24     #plt.grid()
25 25     plt.show()
26 26
27 27plot_acc_loss_curve(history)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM