訓練模型
現在進入最有趣的部分:你要訓練模型了。回想一下,用作預測特徵的資料已載入到名為 predictors 的 NumPy 陣列中,而要被預測的目標資料則存放在名為 target 的 NumPy 陣列中。你的 model 已經預先撰寫好,並且使用上一個練習的程式碼完成了編譯。
本練習屬於課程
Python 深度學習入門
練習說明
- 訓練
model。記得第一個引數是預測特徵(predictors),第二個引數是要被預測的資料(target)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import necessary modules
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
# Specify the model
n_cols = predictors.shape[1]
model = Sequential()
model.add(Dense(50, activation='relu', input_shape = (n_cols,)))
model.add(Dense(32, activation='relu'))
model.add(Dense(1))
# Compile the model
model.compile(optimizer='adam', loss='mean_squared_error')
# Fit the model
____