ปัญหาการสร้างโมเดลเพื่อการพยากรณ์

การสร้างโมเดลด้วยข้อมูลใน Tidyverse

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

ปัญหาการสร้างโมเดล

พิจารณา $y = f(\vec{x}) + \epsilon$

  1. $f()$ และ $\epsilon$ เป็นค่าที่ไม่ทราบ
  2. มีการสังเกต $n$ ครั้งของ $y$ และ $\vec{x}$ ซึ่งให้ไว้ในข้อมูล
  3. เป้าหมาย: สร้างโมเดล $\hat{f}()$ ที่ ประมาณค่า $f()$ โดยละเว้น $\epsilon$
  4. เป้าหมายอีกนัยหนึ่ง: แยก สัญญาณ ออกจาก สัญญาณรบกวน
  5. จากนั้นสร้างค่า fitted/predicted $\hat{y} = \hat{f}(\vec{x})$ ได้
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

ความแตกต่างระหว่างการอธิบายและการพยากรณ์

ความแตกต่างหลักของเป้าหมายในการสร้างโมเดล:

  1. การอธิบาย: ให้ความสำคัญกับรูปแบบของ $\hat{f}()$ โดยเฉพาะค่าที่บ่งบอกความสัมพันธ์ระหว่าง $y$ กับ $\vec{x}$
  2. การพยากรณ์: ไม่ได้สนใจรูปแบบของ $\hat{f}()$ มากนัก แต่ต้องการให้ได้ค่าพยากรณ์ $\hat{y}$ ที่ "ดี" จาก $\vec{x}$
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

สภาพของบ้าน

house_prices %>% 
  select(log10_price, condition) %>% 
  glimpse()
Observations: 21,613
Variables: 2
$ log10_price <dbl> 5.346157, 5.730782, 5.255273...
$ condition   <fct> 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3...
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

การสำรวจข้อมูลด้วยภาพ: boxplot

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

# Apply log10-transformation to outcome variable
house_prices <- house_prices %>%
  mutate(log10_price = log10(price))

# Boxplot ggplot(house_prices, aes(x = condition, y = log10_price)) + geom_boxplot() + labs(x = "house condition", y = "log10 price", title = "log10 house price over condition")
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

การสำรวจข้อมูลด้วยภาพ: boxplot

การสร้างโมเดลด้วยข้อมูลใน Tidyverse

สรุปข้อมูลเชิงสำรวจ

house_prices %>% 
  group_by(condition) %>% 
  summarize(mean = mean(log10_price),
            sd = sd(log10_price), n = n())
# A tibble: 5 x 4
  condition  mean    sd     n
  <fct>     <dbl> <dbl> <int>
1 1          5.42 0.293    30
2 2          5.45 0.233   172
3 3          5.67 0.224 14031
4 4          5.65 0.228  5679
5 5          5.71 0.244  1701
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

สรุปข้อมูลเชิงสำรวจ

# Prediction for new house with condition 4 in dollars
10^(5.65)
446683.6
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

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

การสร้างโมเดลด้วยข้อมูลใน Tidyverse

Preparing Video For Download...