พื้นฐานการสร้างโมเดลเพื่อการพยากรณ์

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

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

ตัวอย่างการสร้างโมเดลเพื่อการพยากรณ์

ชุดข้อมูลราคาบ้านใน King County รัฐ Washington ใกล้กับ Seattle (เผยแพร่ที่ Kaggle.com)

คำถาม: สามารถพยากรณ์ราคาขายบ้านจากคุณสมบัติของบ้านได้หรือไม่?

ตัวแปร:

  • $y$: ราคาขายบ้าน price ในหน่วยดอลลาร์สหรัฐ
  • $\vec{x}$: คุณสมบัติต่าง ๆ เช่น sqft_living, condition, bedrooms, yr_built, waterfront
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

ตัวอย่างการสร้างโมเดลเพื่อการพยากรณ์

จากแพ็กเกจ moderndive สำหรับ ModernDive:

library(dplyr)
library(moderndive)
glimpse(house_prices)
Observations: 21,613
Variables: 21
$ id            <chr> "7129300520", "6414100192"...
$ date          <dttm> 2014-10-13, 2014-12-09, 2015...
$ price         <dbl> 221900, 538000, 180000, 604000...
...
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

การวิเคราะห์ข้อมูลเบื้องต้น

library(ggplot2)
ggplot(house_prices, aes(x = price)) +
  geom_histogram() + 
  labs(x = "house price", y = "count")
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

ฮิสโทแกรมของตัวแปรผลลัพธ์

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

ข้อมูล Gapminder

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

การปรับสเกลแกน x เป็น Log10

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

การแปลงค่าด้วย Log10

# log10() transform price and size
house_prices <- house_prices %>%
  mutate(log10_price = log10(price)) %>% 
  select(price, log10_price)
# A tibble: 21,613 x 2
     price log10_price
     <dbl>       <dbl>
 1  221900        5.35
 2  538000        5.73
 3  180000        5.26
 4  604000        5.78
 5  510000        5.71
 6 1225000        6.09
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

ฮิสโทแกรมของตัวแปรผลลัพธ์ใหม่

# Histogram of original outcome variable
ggplot(house_prices, aes(x = price)) +
  geom_histogram() + 
  labs(x = "house price", y = "count")
# Histogram of new, log10-transformed outcome variable
ggplot(house_prices, aes(x = log10_price)) +
  geom_histogram() + 
  labs(x = "log10 house price", y = "count")
การสร้างโมเดลด้วยข้อมูลใน Tidyverse

เปรียบเทียบก่อนและหลังการแปลงค่าด้วย Log10

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

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

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

Preparing Video For Download...