AdaBoost

Machine Learning with Tree-Based Models in Python

Elie Kawerk

Data Scientist

Boosting

  • Boosting: Ansámblová metoda kombinující více slabých modelů do silného.

  • Slabý model: Model s výsledky jen o něco lepšími než náhodný odhad.

  • Příklad slabého modelu: Rozhodovací pahýl (CART s maximální hloubkou 1).

Machine Learning with Tree-Based Models in Python

Boosting

  • Prediktory se trénují sekvenčně.

  • Každý prediktor opravuje chyby předchozího.

  • Nejpoužívanější metody boostingu:

    • AdaBoost,

    • Gradient Boosting.

Machine Learning with Tree-Based Models in Python

Adaboost

  • Zkratka pro Adaptivní Boosting.

  • Každý prediktor věnuje větší pozornost instancím, které jeho předchůdce špatně předpověděl.

  • Dosahuje se to změnou vah trénovacích instancí.

  • Každému prediktoru je přiřazen koeficient $\alpha$.

  • $\alpha$ závisí na trénovací chybě prediktoru.

Machine Learning with Tree-Based Models in Python

AdaBoost: Trénování

Trénování AdaBoost

Machine Learning with Tree-Based Models in Python

Rychlost učení

Rychlost učení: $0 < \eta \leq 1$ Rychlost učení AdaBoost

Machine Learning with Tree-Based Models in Python

AdaBoost: Predikce

  • Klasifikace:

    • Vážené hlasování majoritou.
    • Ve sklearn: AdaBoostClassifier.
  • Regrese:

    • Vážený průměr.
    • Ve sklearn: AdaBoostRegressor.
Machine Learning with Tree-Based Models in Python

Klasifikace AdaBoost ve sklearn (dataset Breast Cancer)

# Import models and utility functions
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split

# Set seed for reproducibility
SEED = 1

# Split data into 70% train and 30% test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
                                                    stratify=y,
                                                    random_state=SEED)
Machine Learning with Tree-Based Models in Python
# Instantiate a classification-tree 'dt'
dt = DecisionTreeClassifier(max_depth=1, random_state=SEED)

# Instantiate an AdaBoost classifier 'adab_clf' adb_clf = AdaBoostClassifier(base_estimator=dt, n_estimators=100)
# Fit 'adb_clf' to the training set adb_clf.fit(X_train, y_train) # Predict the test set probabilities of positive class y_pred_proba = adb_clf.predict_proba(X_test)[:,1]
# Evaluate test-set roc_auc_score adb_clf_roc_auc_score = roc_auc_score(y_test, y_pred_proba)
Machine Learning with Tree-Based Models in Python

Klasifikace AdaBoost ve sklearn (dataset Breast Cancer)

# Print adb_clf_roc_auc_score
print('ROC AUC score: {:.2f}'.format(adb_clf_roc_auc_score)) 
ROC AUC score: 0.99
Machine Learning with Tree-Based Models in Python

Pojďme cvičit!

Machine Learning with Tree-Based Models in Python

Preparing Video For Download...