Machine Learning dengan Model Berbasis Pohon di R
Sandro Raabe
Data Scientist
Hiperparameter di pohon keputusan parsnip:
min_n: jumlah minimum sampel untuk membagi nodetree_depth: kedalaman maksimum pohoncost_complexity: penalti untuk kompleksitas pohonNilai default yang ditetapkan oleh parsnip:
decision_tree(min_n = 20, tree_depth = 30, cost_complexity = 0.01)
Tujuan penyetelan hiperparameter adalah mencari set nilai hiperparameter yang optimal.




spec_untuned <- decision_tree(min_n = tune(), tree_depth = tune()) %>% set_engine("rpart") %>% set_mode("classification")
Decision Tree Model Specification (classification)Main Arguments: tree_depth = tune() min_n = tune()
tune() menandai parameter untuk diseteltree_grid <- grid_regular(parameters(spec_untuned),levels = 3 )
# A tibble: 9 x 2
min_n tree_depth
1 2 1
2 21 1
3 40 1
4 2 8
5 21 8
6 40 8
7 2 15
8 21 15
9 40 15
parameters()levels: jumlah titik grid per hiperparameter
Penggunaan dan argumen:
metric_set()tune_results <- tune_grid(spec_untuned,outcome ~ .,resamples = my_folds,grid = tree_grid,metrics = metric_set(accuracy))
autoplot(tune_results)

# Pilih parameter dengan kinerja terbaik final_params <- select_best(tune_results)final_params
# A tibble: 1 x 3
min_n tree_depth .config
<int> <int> <chr>
1 2 8 Model4
# Masukkan ke spesifikasi best_spec <- finalize_model(spec_untuned, final_params)best_spec
Decision Tree Model Specification
(classification)
Main Arguments:
tree_depth = 8
min_n = 2
Computational engine: rpart
Machine Learning dengan Model Berbasis Pohon di R