การใช้ smoothing parameters เพื่อป้องกันการ overfit
Smoothing parameter ทำหน้าที่สร้างสมดุลระหว่าง likelihood และความคดเคี้ยวของเส้นโค้ง เพื่อให้โมเดล fit ข้อมูลได้ดีที่สุด ในแบบฝึกหัดนี้ จะได้ศึกษา smoothing parameters และฝึก fit โมเดลด้วยค่า smoothing parameter ที่กำหนดไว้ล่วงหน้าแบบต่างๆ
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสร้างโมเดลแบบไม่เชิงเส้นด้วย Generalized Additive Models (GAMs) ใน R
คำแนะนำการฝึกหัด
- ดูค่า smoothing parameter (\(\lambda\)) ของโมเดล
gam_modที่กำหนดให้ โดยดึงค่าspออกจากโมเดล - Fit โมเดลสองแบบกับข้อมูล
mcycleโดยให้accelเป็น smooth function ของtimesและกำหนด smoothing parameter เป็น:- 0.1
- 0.0001
- Visualize โมเดลทั้งสอง
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
library(mgcv)
# Extract the smoothing parameter
gam_mod <- gam(accel ~ s(times), data = mcycle, method = "REML")
___
# Fix the smoothing parameter at 0.1
gam_mod_s1 <- gam(accel ~ s(times), data = mcycle, sp = ___)
# Fix the smoothing parameter at 0.0001
gam_mod_s2 <- gam(___)
# Plot both models
par(mfrow = c(2, 1))
plot(gam_mod_s1, residuals = TRUE, pch = 1)
plot(gam_mod_s2, residuals = TRUE, pch = 1)