Vítejte v kurzu!

Machine Learning with Tree-Based Models in R

Sandro Raabe

Data Scientist

Přehled kurzu

 

  • Kapitola 1: Klasifikační stromy
  • Kapitola 2: Regresní stromy, křížová validace, kompromis vychýlení a rozptylu
  • Kapitola 3: Ladění hyperparametrů, bagging, náhodné lesy
  • Kapitola 4: Posílené stromy
Machine Learning with Tree-Based Models in R

Rozhodovací stromy jsou vývojové diagramy

Vývojový diagram pro zvířata

1 https://aca.edu.au/resources/decision-trees-classifying-animals/decision-trees.pdf
Machine Learning with Tree-Based Models in R

Výhody stromových modelů

  • Snadno vysvětlitelné a srozumitelné
  • Schopné zachytit nelineární vztahy
  • Nevyžadují normalizaci ani standardizaci číselných příznaků
  • Není třeba vytvářet indikátorové proměnné
  • Robustní vůči odlehlým hodnotám
  • Rychlé pro velké datové sady
Machine Learning with Tree-Based Models in R

Nevýhody stromových modelů

  • Obtížně interpretovatelné při velké hloubce nebo v ansámblu
  • Vysoký rozptyl, složité stromy jsou náchylné k přetrénování
Machine Learning with Tree-Based Models in R

Snímek obrazovky tidymodels

Machine Learning with Tree-Based Models in R

Balíček tidymodels

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
Machine Learning with Tree-Based Models in R

Vytvoření rozhodovacího stromu

Specifikace / funkční návrh

 1. Vyberte třídu modelu

library(tidymodels)

decision_tree()
Decision Tree Model Specification (unknown)
Machine Learning with Tree-Based Models in R

Vytvoření rozhodovacího stromu

 2. Nastavte engine, který pohání váš model

library(tidymodels)

decision_tree() %>% 
    set_engine("rpart")
Decision Tree Model Specification (unknown)

Computational engine: rpart
Machine Learning with Tree-Based Models in R

Vytvoření rozhodovacího stromu

 3. Nastavte režim (klasifikace nebo regrese)

library(tidymodels)

decision_tree() %>% 
     set_engine("rpart") %>% 
     set_mode("classification")
Decision Tree Model Specification (classification)

Computational engine: rpart
Machine Learning with Tree-Based Models in R

Od specifikace modelu k reálnému modelu

Specifikace je kostra a potřebuje data pro trénování
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

Pojďme sestavit model!

Machine Learning with Tree-Based Models in R

Preparing Video For Download...