Huấn luyện mô hình
Đến phần thú vị nhất rồi! Giờ bạn sẽ huấn luyện mô hình. Nhắc lại: dữ liệu dùng làm đặc trưng dự đoán được nạp trong NumPy array tên là predictors và dữ liệu cần dự đoán được lưu trong NumPy array tên là target. model của bạn đã được viết sẵn và đã được compile bằng đoạn mã từ bài tập trước.
Bài tập này là một phần của khóa học
Nhập môn Deep Learning với Python
Hướng dẫn bài tập
- Huấn luyện
model. Nhớ rằng đối số thứ nhất là các đặc trưng dự đoán (predictors), và dữ liệu cần dự đoán (target) là đối số thứ hai.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# 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
____