Machine Learning with Tree-Based Models in R
Sandro Raabe
Data Scientist
tree_depth
?decision_tree
Simple model
simple_spec <- decision_tree(tree_depth = 2) %>%
set_mode("regression")
simple_spec %>% fit(final_grade ~ .,
data = training_data)
Complex model
complex_spec <- decision_tree(tree_depth = 15) %>%
set_mode("regression")
complex_spec %>% fit(final_grade ~ .,
data = training_data)
Predictions on training set: well done!
mae(train_results,
estimate = .pred,
truth = final_grade)
# A tibble: 1 x 3
.metric .estimate
1 mae 0.204
Predictions on test set: not even close!
mae(test_results,
estimate = .pred,
truth = final_grade)
# A tibble: 1 x 3
.metric .estimate
1 mae 0.947
Large errors on training and test set:
bind_rows(training = mae(train_results, estimate = .pred, truth = final_grade),
test = mae(test_results, estimate = .pred, truth = final_grade),
.id = "dataset")
# A tibble: 2 x 4
dataset .metric .estimate
<chr> <chr> <dbl>
1 training mae 0.754
2 test mae 0.844
Out-of-sample/CV:
collect_metrics(cv_fits)
# A tibble: 1 x 3
.metric mean n
1 mae 2.432 5
In-sample:
mae(training_pred,
estimate = .pred,
truth = final_grade)
# A tibble: 1 x 2
.metric .estimate
1 mae 0.228
In-sample:
mae(training_pred, estimate = .pred, truth = final_grade)
# A tibble: 1 x 2
.metric .estimate
<chr> <dbl>
1 mae 2.432
Machine Learning with Tree-Based Models in R