R에서 tidymodels로 모델링하기
David Svancer
Data Scientist
레이블이 있는 데이터로 모델을 학습하는 머신 러닝 분야
회귀
분류
| left_company | miles_from_home | salary |
|---|---|---|
| no | 1 | 84500 |
| yes | 10 | 64820 |
| no | 5 | 76490 |
| yes | 19 | 68540 |
tidymodels 변수 역할
훈련/테스트 세트 생성
훈련 데이터
테스트 데이터
미국 환경보호청(EPA)의 차량 연비 데이터
hwy - 고속도로 연비(mpg)mpg
# A tibble: 234 x 11
hwy cty displ cyl manufacturer model year trans drv fl class
<int> <int> <dbl> <int> <chr> <chr> <int> <chr> <chr> <chr> <chr>
1 29 18 1.8 4 audi a4 1999 auto(l5) f p compact
2 29 21 1.8 4 audi a4 1999 manual(m5) f p compact
3 31 20 2 4 audi a4 2008 manual(m6) f p compact
4 30 21 2 4 audi a4 2008 auto(av) f p compact
5 26 16 2.8 6 audi a4 1999 auto(l5) f p compact
# ... with 224 more rows
initial_split()
prop은 훈련에 넣을 비율strata는 결과 변수로 층화분할 객체를 training()에 전달
testing()에 전달library(tidymodels)
mpg_split <- initial_split(mpg,
prop = 0.75,
strata = hwy)
mpg_training <- mpg_split %>%
training()
mpg_test <- mpg_split %>%
testing()
2015~2016년 워싱턴주 시애틀 지역의 주택 판매
home_sales
# A tibble: 1,492 x 8
selling_price home_age bedrooms bathrooms sqft_living sqft_lot sqft_basement floors
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 487000 10 4 2.5 2540 5001 0 2
2 465000 10 3 2.25 1530 1245 480 2
3 411000 18 2 2 1130 1148 330 2
4 635000 4 3 2.5 3350 4007 800 2
5 380000 24 5 2.5 2130 8428 0 2
# ... with 1,482 more rows
R에서 tidymodels로 모델링하기