การ Fit โมเดล
มาถึงส่วนที่สนุกที่สุดแล้ว นั่นคือการ fit โมเดล ข้อมูลที่ใช้เป็น feature สำหรับการพยากรณ์ถูกโหลดไว้ใน NumPy array ชื่อ predictors และข้อมูลที่ต้องการพยากรณ์ถูกเก็บไว้ใน NumPy array ชื่อ target ส่วน model นั้นเขียนไว้ให้แล้ว และได้ compile ด้วยโค้ดจากแบบฝึกหัดก่อนหน้าเรียบร้อยแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Introduction to Deep Learning in Python
คำแนะนำการฝึกหัด
- Fit
modelโดยจำไว้ว่าอาร์กิวเมนต์แรกคือ feature สำหรับการพยากรณ์ (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
____