模型评估与选择

Tidyverse 的数据建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

复习:多元回归

两个使用不同自变量/预测变量组合的模型:

# 模型 1 - 两个数值变量:
model_price_1 <- lm(log10_price ~ log10_size + yr_built, 
                    data = house_prices)

# 模型 3 - 一个数值变量 & 一个分类变量: model_price_3 <- lm(log10_price ~ log10_size + condition, data = house_prices)
Tidyverse 的数据建模

复习:残差平方和

Tidyverse 的数据建模

复习:残差平方和

# 模型 1
model_price_1 <- lm(log10_price ~ log10_size + yr_built, 
                    data = house_prices)
get_regression_points(model_price_1) %>%
  mutate(sq_residuals = residual^2) %>%
  summarize(sum_sq_residuals = sum(sq_residuals))
# A tibble: 1 x 1
  sum_sq_residuals
             <dbl>
1             585.
Tidyverse 的数据建模

复习:残差平方和

# 模型 3
model_price_3 <- lm(log10_price ~ log10_size + condition, 
                    data = house_prices)

get_regression_points(model_price_3) %>%
  mutate(sq_residuals = residual^2) %>%
  summarize(sum_sq_residuals = sum(sq_residuals))
# A tibble: 1 x 1
  sum_sq_residuals
             <dbl>
1             608.
Tidyverse 的数据建模

让我们来练习!

Tidyverse 的数据建模

Preparing Video For Download...