Stop 09 · Trees & Ensemble MethodsTopics · 4/8

Boosting Explained (AdaBoost)

Part of the Machine Learning Roadmap

In short

Bagging trains many models side by side. Boosting trains them one after another, each new one focusing on what the previous ones got wrong. AdaBoost was the first boosting method to work really well, and it explains the idea behind XGBoost and LightGBM.

Boosting builds models one after another, each focusing on the examples earlier models got wrong. AdaBoost does this by increasing the weight of misclassified examples, combining many weak learners into a strong one.

The jaadu as a tuition teacher circles a few answers on a stack of answer sheets, then places those sheets on top of a taller pile for the next class.

Think of it like this

The tuition teacher's revision

After the first mock test, a tuition teacher doesn't re-teach everything. She circles the questions students got wrong and spends the next class on those. After the second test, she circles the new mistakes. Each round focuses on the hardest questions. AdaBoost does this with data: misclassified rows get more weight, and the next weak model works on them.

Watch it happen

Three rounds of AdaBoost

Equal weights
Stump 1
Reweight
Stump 2, 3...
Weighted vote

1/5Start: every one of 1,000 training rows has weight 1/1000.

The big ideas

What you need to know

Weak learners

Each model only needs to be a little better than guessing. Depth-1 trees, called stumps, are the classic choice.

Reweight mistakes

Wrongly classified rows get heavier after each round, so later models are forced to deal with them.

Weighted vote

Accurate models get a bigger say. The combined model can be strong even though each part is weak.

Sensitive to noise

Mislabelled rows keep getting heavier, so AdaBoost can chase noise. Clean labels and a moderate learning_rate help.

See it in code

Walk through the code

python
1from sklearn.datasets import make_classification2from sklearn.ensemble import AdaBoostClassifier3from sklearn.model_selection import train_test_split4from sklearn.tree import DecisionTreeClassifier5 6X, y = make_classification(n_samples=2000, n_features=10, n_informative=5, random_state=0)7X_tr, X_te, y_tr, y_te = train_test_split(X, y, random_state=0)8 9stump = DecisionTreeClassifier(max_depth=1).fit(X_tr, y_tr)10print("One stump:", round(stump.score(X_te, y_te), 3))11 12ada = AdaBoostClassifier(13    estimator=DecisionTreeClassifier(max_depth=1),14    n_estimators=300,15    learning_rate=0.5,16    random_state=0,17).fit(X_tr, y_tr)18print("AdaBoost:", round(ada.score(X_te, y_te), 3))19 20for i, score in enumerate(ada.staged_score(X_te, y_te)):21    if i in (0, 9, 49, 299):22        print(i + 1, "stumps:", round(score, 3))

1/3A single one-split tree as a baseline. It's only a bit better than guessing on this data.

One stump is weak. Three hundred boosted stumps are strong.

Save yourself the pain

Common mistakes

Oops

Using deep trees as the base estimator in AdaBoost.

Do this instead

Use weak learners like stumps or depth 2 to 3 trees. Deep trees overfit on the first round and leave nothing to boost.

Oops

Thinking more rounds can never hurt.

Do this instead

With noisy labels, too many rounds overfit. Use staged_score on validation data to choose n_estimators.

Your mission

Watch boosting learn

~25 min

Quick check

After each round of AdaBoost, what happens to the training rows the latest model got wrong?

Go deeper

  1. 1Train AdaBoostClassifier with decision stumps and plot accuracy as estimators are added.
  2. 2Explain the difference between bagging and boosting in two sentences.
  3. 3Try different learning_rate values and watch for overfitting.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge