在驗證資料集上評估模型準確率
現在換你用驗證資料集來監控模型的準確率。已經提供好名為 model 的模型定義。你的工作是補上編譯與訓練的程式碼,並在每個 epoch 檢查驗證分數。
本練習屬於課程
Python 深度學習入門
練習說明
- 使用
'adam'作為optimizer,'categorical_crossentropy'作為loss來編譯模型。若要在每個 epoch 看到正確預測的比例(accuracy),請在model.compile()中加入額外的關鍵字參數metrics=['accuracy']。 - 使用
predictors與target來訓練模型。建立 30%(或0.3)的驗證分割。系統會在每個 epoch 回報這個結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Save the number of columns in predictors: n_cols
n_cols = predictors.shape[1]
input_shape = (n_cols,)
# Specify the model
model = Sequential()
model.add(Dense(100, activation='relu', input_shape = input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))
# Compile the model
____
# Fit the model
hist = ____