선형 회귀 - 기본 방법

R로 하는 Supervised Learning: 회귀

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$에 가산적으로 기여
R로 하는 Supervised Learning: 회귀

R에서의 선형 회귀: lm()

cmodel <- lm(temperature ~ chirps_per_sec, data = cricket)
  • 공식: temperature ~ chirps_per_sec
  • 데이터 프레임: cricket
R로 하는 Supervised Learning: 회귀

공식

fmla_1 <- temperature ~ chirps_per_sec
fmla_2 <- blood_pressure ~ age + weight
  • 좌변: 결과 변수
  • 우변: 입력 변수
    • 여러 입력 변수는 + 사용
fmla_1 <- as.formula("temperature ~ chirps_per_sec")
R로 하는 Supervised Learning: 회귀

모델 살펴보기

$$ 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
R로 하는 Supervised Learning: 회귀

모델 추가 정보

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
R로 하는 Supervised Learning: 회귀

모델 추가 정보

broom::glance(cmodel)

sigr::wrapFTest(cmodel)
R로 하는 Supervised Learning: 회귀

연습해 봅시다!

R로 하는 Supervised Learning: 회귀

Preparing Video For Download...