การถดถอยเชิงเส้น — วิธีพื้นฐาน

Supervised Learning ใน R: การถดถอย

Nina Zumel and John Mount

Win-Vector LLC

การถดถอยเชิงเส้น

$$y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + ...$$

  • $y$ สัมพันธ์กับ $x_i$ แต่ละตัวแบบ เชิงเส้น
  • $x_i$ แต่ละตัวมีผลต่อ $y$ แบบ บวกสะสม
Supervised Learning ใน R: การถดถอย

การถดถอยเชิงเส้นใน R: lm()

cmodel <- lm(temperature ~ chirps_per_sec, data = cricket)
  • สูตร: temperature ~ chirps_per_sec
  • data frame: cricket
Supervised Learning ใน R: การถดถอย

สูตร (Formulas)

fmla_1 <- temperature ~ chirps_per_sec
fmla_2 <- blood_pressure ~ age + weight
  • LHS: ตัวแปรผลลัพธ์
  • RHS: ตัวแปรอินพุต
    • ใช้ + สำหรับหลายอินพุต
fmla_1 <- as.formula("temperature ~ chirps_per_sec")
Supervised Learning ใน R: การถดถอย

ดูผลลัพธ์ของโมเดล

$$ y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + ... $$

cmodel
Call:
lm(formula = temperature ~ chirps_per_sec, data = cricket)

Coefficients:
   (Intercept)  chirps_per_sec  
        25.232           3.291
Supervised Learning ใน R: การถดถอย

ข้อมูลเพิ่มเติมเกี่ยวกับโมเดล

summary(cmodel)
Call:
lm(formula = fmla, data = cricket)

Residuals:
   Min     1Q Median     3Q    Max 
-6.515 -1.971  0.490  2.807  5.001 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)     25.2323    10.0601   2.508 0.026183 *  
chirps_per_sec   3.2911     0.6012   5.475 0.000107 ***

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3.829 on 13 degrees of freedom
Multiple R-squared:  0.6975, Adjusted R-squared:  0.6742 
F-statistic: 29.97 on 1 and 13 DF,  p-value: 0.0001067
Supervised Learning ใน R: การถดถอย

ข้อมูลเพิ่มเติมเกี่ยวกับโมเดล

broom::glance(cmodel)

sigr::wrapFTest(cmodel)
Supervised Learning ใน R: การถดถอย

มาฝึกกันเถอะ!

Supervised Learning ใน R: การถดถอย

Preparing Video For Download...