AdaBoost

Machine Learning with Tree-Based Models in Python

Elie Kawerk

Data Scientist

Boosting

  • Boosting: วิธี Ensemble ที่รวม Weak Learner หลายตัวเพื่อสร้าง Strong Learner

  • Weak learner: โมเดลที่ทำนายได้ดีกว่าการเดาสุ่มเล็กน้อย

  • ตัวอย่าง Weak learner: Decision stump (CART ที่มีความลึกสูงสุดเท่ากับ 1)

Machine Learning with Tree-Based Models in Python

Boosting

  • เทรน Ensemble ของ Predictor ตามลำดับ

  • แต่ละ Predictor พยายามแก้ข้อผิดพลาดของตัวก่อนหน้า

  • วิธี Boosting ที่นิยมมากที่สุด:

    • AdaBoost,

    • Gradient Boosting.

Machine Learning with Tree-Based Models in Python

Adaboost

  • ย่อมาจาก Adaptive Boosting

  • แต่ละ Predictor จะให้ความสำคัญกับตัวอย่างที่ Predictor ก่อนหน้าทำนายผิด

  • ทำได้โดยการปรับน้ำหนักของข้อมูลเทรน

  • แต่ละ Predictor จะได้รับค่าสัมประสิทธิ์ $\alpha$

  • $\alpha$ ขึ้นอยู่กับค่า Training Error ของ Predictor

Machine Learning with Tree-Based Models in Python

AdaBoost: การเทรน

การเทรน AdaBoost

Machine Learning with Tree-Based Models in Python

Learning Rate

Learning rate: $0 < \eta \leq 1$ AdaBoost learning rate

Machine Learning with Tree-Based Models in Python

AdaBoost: การทำนาย

  • การจำแนกประเภท:

    • Weighted Majority Voting
    • ใน sklearn: AdaBoostClassifier
  • การถดถอย:

    • Weighted Average
    • ใน sklearn: AdaBoostRegressor
Machine Learning with Tree-Based Models in Python

AdaBoost Classification ใน sklearn (ชุดข้อมูล 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

AdaBoost Classification ใน sklearn (ชุดข้อมูล 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

มาฝึกกันเถอะ!

Machine Learning with Tree-Based Models in Python

Preparing Video For Download...