8.35 Build a model
Split dataset into train/test
set.seed(1234)
<- initial_split(carseats, prop = 0.75, strata = High)
carseats_split
<- training(carseats_split)
carseats_train <- testing(carseats_split) carseats_test
Create decision tree classification spec
<- decision_tree() %>%
class_tree_spec set_engine("rpart") %>%
set_mode("classification")
Fit the decision tree model
<- fit(class_tree_spec, High ~ ., data = carseats_train) class_tree_fit