Učení klasifikačního stromu

Machine Learning with Tree-Based Models in Python

Elie Kawerk

Data Scientist

Stavební bloky rozhodovacího stromu

  • Rozhodovací strom: datová struktura tvořená hierarchií uzlů.

  • Uzel: otázka nebo predikce.

Machine Learning with Tree-Based Models in Python

Stavební bloky rozhodovacího stromu

Tři typy uzlů:

  • Kořen: žádný rodičovský uzel, otázka vedoucí ke dvěma dětským uzlům.

  • Vnitřní uzel: jeden rodičovský uzel, otázka vedoucí ke dvěma dětským uzlům.

  • List: jeden rodičovský uzel, žádné dětské uzly --> predikce.

Machine Learning with Tree-Based Models in Python

Predikce

Označený rozhodovací strom

Machine Learning with Tree-Based Models in Python

Informační zisk (IG)

Diagram informačního zisku

Machine Learning with Tree-Based Models in Python

Informační zisk (IG)

Vzorec informačního zisku

Kritéria pro měření nečistoty uzlu $I (node)$:

  • Giniho index,
  • entropie. ...
Machine Learning with Tree-Based Models in Python

Učení klasifikačního stromu

  • Uzly se rozvíjejí rekurzivně.

  • V každém uzlu se data rozdělí podle:

    • příznaku $f$ a dělicího bodu $sp$ pro maximalizaci $IG(\text{node})$.
  • Pokud $IG (\text{node})$= 0, uzel se označí jako list.

    ...

Machine Learning with Tree-Based Models in Python
# Import DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier
# Import train_test_split
from sklearn.model_selection import train_test_split
# Import accuracy_score
from sklearn.metrics import accuracy_score
# Split dataset into 80% train, 20% test
X_train, X_test, y_train, y_test= train_test_split(X, y, 
                                                   test_size=0.2, 
                                                   stratify=y,
                                                   random_state=1)
# Instantiate dt, set 'criterion' to 'gini'
dt = DecisionTreeClassifier(criterion='gini', random_state=1)
Machine Learning with Tree-Based Models in Python

Informační kritérium v scikit-learn

# Fit dt to the training set
dt.fit(X_train,y_train)

# Predict test-set labels
y_pred= dt.predict(X_test)

# Evaluate test-set accuracy
accuracy_score(y_test, y_pred)
0.92105263157894735
Machine Learning with Tree-Based Models in Python

Pojďme procvičovat!

Machine Learning with Tree-Based Models in Python

Preparing Video For Download...