要求:查看存儲在Training中的訓練過程,並分別畫出loss,acc,val_loss,val_acc隨時期(Epoch)的變化曲線,代碼如下(可供參考):
#以epoch為橫坐標,在同一坐標下畫出acc、val_acc隨epoch變化的曲線圖 #定義show_Training_history()函數,輸入參數:訓練過程所產生的Training_history import matplotlib.pyplot as plt def show_Training_history(Training_history, train, validation): # 訓練數據執行結果,’-‘表示實線,’b'表示藍色 plt.plot(Training.history[train], linestyle='-', color='b') # 驗證數據執行結果,‘--’表示虛線,‘r'表示紅色 plt.plot(Training.history[validation], linestyle='--', color='r') # 顯示圖的標題 plt.title('Training accuracy history') # 顯示x軸標簽epoch plt.xlabel('epoch') # 顯示y軸標簽train plt.ylabel('train') # 設置圖例是顯示'train','validation',位置在右下角 plt.legend(['train', 'validation'], loc='lower right') # 開始繪圖 plt.show() # 調用show_Training_history()函數,輸入參數:訓練過程中產生的Training,acc,val_acc show_Training_history(Training, 'acc', 'val_acc')