編譯與訓練模型

Python 深度學習入門

Dan Becker

Data Scientist and contributor to Keras and TensorFlow libraries

為什麼要先編譯模型

  • 指定最佳化器
    • 選項多且數學較複雜
    • 「Adam」通常是不錯的選擇
  • 損失函式
    • 「mean_squared_error」常用於迴歸
Python 深度學習入門

編譯模型

n_cols = predictors.shape[1]
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=(n_cols,)))
model.add(Dense(100, activation='relu'))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mean_squared_error')
Python 深度學習入門

什麼是擬合模型

  • 以你的資料執行反向傳播與梯度下降來更新權重
  • 擬合前先縮放資料可讓最佳化更順暢
Python 深度學習入門

擬合模型

n_cols = predictors.shape[1]
model = Sequential()
model.add(Dense(100, activation='relu', input_shape=(n_cols,)))
model.add(Dense(100, activation='relu'))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(predictors, target)
Python 深度學習入門

一起來練習吧!

Python 深度學習入門

Preparing Video For Download...