模型評估與選擇

在 Tidyverse 中進行資料建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

複習:多元迴歸

兩個模型,使用不同的解釋/預測變數組合:

# Model 1 - Two numerical:
model_price_1 <- lm(log10_price ~ log10_size + yr_built, 
                    data = house_prices)

# Model 3 - One numerical & one categorical: model_price_3 <- lm(log10_price ~ log10_size + condition, data = house_prices)
在 Tidyverse 中進行資料建模

複習:殘差平方和

在 Tidyverse 中進行資料建模

複習:殘差平方和

# Model 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 中進行資料建模

複習:殘差平方和

# Model 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...