Machine Learning với Mô hình Dựa trên Cây trong R
Sandro Raabe
Data Scientist
tree_depth?decision_tree

Mô hình đơn giản
simple_spec <- decision_tree(tree_depth = 2) %>%
set_mode("regression")
simple_spec %>% fit(final_grade ~ .,
data = training_data)
Mô hình phức tạp
complex_spec <- decision_tree(tree_depth = 15) %>%
set_mode("regression")
complex_spec %>% fit(final_grade ~ .,
data = training_data)


Dự đoán trên tập huấn luyện: rất tốt!

mae(train_results,
estimate = .pred,
truth = final_grade)
# A tibble: 1 x 3
.metric .estimate
1 mae 0.204
Dự đoán trên tập kiểm tra: lệch xa!

mae(test_results,
estimate = .pred,
truth = final_grade)
# A tibble: 1 x 3
.metric .estimate
1 mae 0.947
Lỗi lớn trên cả tập huấn luyện và kiểm tra:
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

Ngoài mẫu/CV:
collect_metrics(cv_fits)
# A tibble: 1 x 3
.metric mean n
1 mae 2.432 5
Trong mẫu:
mae(training_pred,
estimate = .pred,
truth = final_grade)
# A tibble: 1 x 2
.metric .estimate
1 mae 0.228
Trong mẫu:
mae(training_pred, estimate = .pred, truth = final_grade)
# A tibble: 1 x 2
.metric .estimate
<chr> <dbl>
1 mae 2.432
Machine Learning với Mô hình Dựa trên Cây trong R