เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การพยากรณ์ผลผลิต

ส่วนที่น่าสนุกของการสร้างโมเดลคือการนำโมเดลไปใช้พยากรณ์ผลลัพธ์ ทำได้โดยเรียกใช้ predict() ในรูปแบบต่อไปนี้

predict(model, cases_to_predict, type = "response")

โหลด mgcv และ dplyr ไว้แล้ว โดย GAM ของชุดข้อมูลข้าวโพดและข้าวสาลีพร้อมใช้งานในชื่อ corn_model และ wheat_model ตามลำดับ และมี character vector ของภูมิภาคสำมะโนประชากรเก็บไว้ในตัวแปร census_regions

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Writing Functions in 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 = ___)
แก้ไขและรันโค้ด