根據模型訓練結果繪制准確率和損失值曲線圖


 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