8.35 Build a model

Split dataset into train/test

set.seed(1234)
carseats_split <- initial_split(carseats, prop = 0.75, strata = High)

carseats_train <- training(carseats_split)
carseats_test <- testing(carseats_split)

Create decision tree classification spec

class_tree_spec <- decision_tree() %>% 
     set_engine("rpart") %>% 
     set_mode("classification")

Fit the decision tree model

class_tree_fit <- fit(class_tree_spec, High ~ ., data = carseats_train)