拟合模型
现在进入最有趣的部分:拟合模型。请回忆,用作预测特征的数据已加载在名为 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
____