나이를 이용한 강의 점수 예측

Tidyverse로 하는 데이터 모델링

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

복습: 회귀선

Tidyverse로 하는 데이터 모델링

신규 강사 예측

Tidyverse로 하는 데이터 모델링

복습: 회귀 테이블

library(ggplot2)
library(dplyr)
library(moderndive)

# Fit regression model using formula of form: y ~ x
model_score_1 <- lm(score ~ age, data = evals)

# Output regression table using wrapper function
get_regression_table(model_score_1)
# A tibble: 2 x 7
  term      estimate std_error statistic p_value lower_ci...
  <chr>        <dbl>     <dbl>     <dbl>   <dbl>    <dbl>...
1 intercept    4.46      0.127     35.2    0        4.21...
2 age         -0.006     0.003     -2.31   0.021   -0.011...
Tidyverse로 하는 데이터 모델링

예측값

  • 일반 예측 회귀 모델: $\hat{y} = \hat{f}(x) = \hat{\beta}_0 + \hat{\beta}_1 \cdot x$
  • 예측 모델: $\hat{\text{score}} = 4.46 - 0.006 \cdot \text{age}$
  • 예측값: $4.46 - 0.006 \cdot 40 = 4.22$
Tidyverse로 하는 데이터 모델링

예측 오차

Tidyverse로 하는 데이터 모델링

예측 오차

Tidyverse로 하는 데이터 모델링

모델 오차로서의 잔차

  • 잔차 = $y - \hat{y}$
  • $y = f(\vec{x}) + \epsilon$에서 $\epsilon$에 해당
  • 예시 강사: $y - \hat{y} = 3.5 - 4.22 = -0.72$
  • 선형 회귀에서 잔차의 평균은 0입니다.
Tidyverse로 하는 데이터 모델링

모든 예측값 계산

# Fit regression model using formula of form: y ~ x
model_score_1 <- lm(score ~ age, data = evals)

# Get information on each point get_regression_points(model_score_1)
# A tibble: 463 x 5
      ID score   age score_hat residual
   <int> <dbl> <dbl>     <dbl>    <dbl>
 1     1   4.7    36      4.25    0.452
 2     2   4.1    36      4.25   -0.148
 3     3   3.9    36      4.25   -0.348
 4     4   4.8    36      4.25    0.552
 5     5   4.6    59      4.11    0.488
Tidyverse로 하는 데이터 모델링

"최적" 회귀선

Tidyverse로 하는 데이터 모델링

연습해 봅시다!

Tidyverse로 하는 데이터 모델링

Preparing Video For Download...