开始使用免费开始使用

在验证数据集上评估模型准确率

现在轮到您使用验证数据集来监控模型的准确率了。已为您提供名为 model 的模型定义。您的任务是补充代码来编译并训练它。您将查看每个 epoch 的验证分数。

本练习是课程的一部分

Python 深度学习入门

查看课程

练习说明

  • 使用 'adam' 作为 optimizer'categorical_crossentropy' 作为 loss 来编译模型。为在每个 epoch 中查看预测正确的比例(accuracy),在 model.compile() 中额外指定关键字参数 metrics=['accuracy']
  • 使用 predictorstarget 来训练模型。创建 30%(即 0.3)的验证集划分。该结果会在每个 epoch 中报告。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Save the number of columns in predictors: n_cols
n_cols = predictors.shape[1]
input_shape = (n_cols,)

# Specify the model
model = Sequential()
model.add(Dense(100, activation='relu', input_shape = input_shape))
model.add(Dense(100, activation='relu'))
model.add(Dense(2, activation='softmax'))

# Compile the model
____

# Fit the model
hist = ____
编辑并运行代码