Machine Learning with Tree-Based Models in R
Sandro Raabe
Data Scientist
library(tidymodels)
-- Attaching packages -------------------- tidymodels 0.1.4 --
v parsnip 0.2.1 v rsample 0.1.1
v dplyr 1.0.9 v tibble 3.1.7
v yardstick 0.0.9 v tune 0.1.6
1. Pick a model class
library(tidymodels)
decision_tree()
Decision Tree Model Specification (unknown)
2. Set the engine that powers your model
library(tidymodels)
decision_tree() %>%
set_engine("rpart")
Decision Tree Model Specification (unknown)
Computational engine: rpart
3. Set the mode (classification or regression)
library(tidymodels)
decision_tree() %>%
set_engine("rpart") %>%
set_mode("classification")
Decision Tree Model Specification (classification)
Computational engine: rpart
library(tidymodels)
tree_spec <- decision_tree() %>%
set_engine("rpart") %>%
set_mode("classification")
# A model specification is fit using a formula to training data
tree_spec %>%
fit(formula = outcome ~ age + bmi,
data = diabetes)
parsnip model object
Fit time: 19 ms
n = 652
Machine Learning with Tree-Based Models in R