11.2 Decision trees

https://tidymodels.github.io/parsnip/articles/articles/Models.html

Fit a decision tree using rpart

rt_spec <- parsnip::decision_tree() %>%
  parsnip::set_engine("rpart") %>%
  parsnip::set_mode("regression")
rt_wf <- lm_wf %>%
  workflows::update_model(rt_spec)
rt_wf
## ══ Workflow ═════════════════════════════════════════════════════════════════
## Preprocessor: Formula
## Model: decision_tree()
## 
## ── Preprocessor ─────────────────────────────────────────────────────────────
## Sale_Price ~ Gr_Liv_Area
## 
## ── Model ────────────────────────────────────────────────────────────────────
## Decision Tree Model Specification (regression)
## 
## Computational engine: rpart
rt_wf %>%
  tune::last_fit(ames_split) %>%
  tune::collect_metrics()
## # A tibble: 2 x 3
##   .metric .estimator .estimate
##   <chr>   <chr>          <dbl>
## 1 rmse    standard   54906.   
## 2 rsq     standard       0.452