天天看點

畫出訓練過程随時期(Epoch)的變化曲線

要求:檢視存儲在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')