进行产量预测
建模中最有趣的部分就是用模型做预测。您可以按如下方式调用 predict() 完成预测。
predict(model, cases_to_predict, type = "response")
已加载 mgcv 和 dplyr;玉米和小麦数据集的 GAM 分别保存为 corn_model 和 wheat_model。人口普查区域的字符向量存为 census_regions。
本练习是课程的一部分
R 函数编写入门
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Make predictions in 2050
predict_this <- data.frame(
year = ___,
census_region = census_regions
)
# Predict the yield
pred_yield_kg_per_ha <- ___(___, ___, type = "response")
predict_this %>%
# Add the prediction as a column of predict_this
___(pred_yield_kg_per_ha = ___)