AdaBoost

Python 树模型机器学习

Elie Kawerk

Data Scientist

Boosting

  • Boosting:集成方法,将多个弱学习器组合为强学习器。

  • 弱学习器:性能略优于随机猜测的模型。

  • 弱学习器示例:决策树桩(最大深度为 1 的 CART)。

Python 树模型机器学习

Boosting

  • 顺序训练一组预测器。

  • 每个预测器纠正其前驱的错误。

  • 常见的 boosting 方法:

    • AdaBoost,

    • 梯度提升。

Python 树模型机器学习

Adaboost

  • 意为自适应提升(Adaptive Boosting)。

  • 每个预测器更关注前一模型误分的样本。

  • 通过调整训练样本权重实现。

  • 每个预测器分配一个系数 $\alpha$。

  • $\alpha$ 取决于该预测器的训练误差。

Python 树模型机器学习

AdaBoost:训练

ada-train

Python 树模型机器学习

学习率

学习率:$0 < \eta \leq 1$ ada-lr

Python 树模型机器学习

AdaBoost:预测

  • 分类:

    • 加权多数投票。
    • 在 sklearn 中:AdaBoostClassifier
  • 回归:

    • 加权平均。
    • 在 sklearn 中:AdaBoostRegressor
Python 树模型机器学习

sklearn 中的 AdaBoost 分类(乳腺癌数据集)

# 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)
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)
Python 树模型机器学习

sklearn 中的 AdaBoost 分类(乳腺癌数据集)

# Print adb_clf_roc_auc_score
print('ROC AUC score: {:.2f}'.format(adb_clf_roc_auc_score)) 
ROC AUC score: 0.99
Python 树模型机器学习

Passons à la pratique !

Python 树模型机器学习

Preparing Video For Download...