Start learning

AdaBoost

Lesson 36. About 6 minutes.

AdaBoost (adaptive boosting) trains a sequence of tiny trees. After each one, it increases the weight of the rows that were misclassified, so the next tree concentrates on the hard cases. Better trees get a bigger say in the final vote.

Your Path Through This Lesson

0 of 5 done

By the End of This Lesson You Can
  • Walk through one round of AdaBoost by hand.
  • Compute a stump's "amount of say" and the new row weights.
  • Train and tune AdaBoostClassifier.

The Algorithm

AdaBoost usually uses stumps: trees with a single question. Each stump on its own is barely better than guessing.

  1. Give every training row the same weight, .
  2. Train a stump using these weights.
  3. Compute its weighted error : the total weight of the rows it got wrong.
  4. Give the stump an amount of say:
  1. Update the weights: multiply misclassified rows by and correct rows by , then rescale so they add up to 1.
  2. Repeat from step 2.

Prediction: every stump votes, and each vote counts times. The class with the larger total wins.

The Amount of Say

Weighted error Meaning
0.01 2.30 Almost perfect: a big say
0.30 0.42 Decent
0.50 0 No better than a coin flip: no say
0.70 −0.42 Worse than a coin flip: its vote is flipped

One Round by Hand

Ten rows, each starting with weight 0.1. The first stump gets 3 rows wrong, so .

New weights before rescaling:

  • Each wrong row: . Three of them: 0.458.
  • Each right row: . Seven of them: 0.458.

Rescale so the total is 1 (divide by 0.916):

  • Each wrong row: 0.167. Each right row: 0.071.

Each misclassified row now weighs more than twice as much as a correct one. In fact, the three hard rows now hold exactly half of the total weight, so the next stump can't ignore them.

python
import numpy as np

w = np.full(10, 0.1)
wrong = np.array([1, 1, 1, 0, 0, 0, 0, 0, 0, 0], dtype=bool)

eps = w[wrong].sum()
alpha = 0.5 * np.log((1 - eps) / eps)
w = w * np.where(wrong, np.exp(alpha), np.exp(-alpha))
w = w / w.sum()

print(f"alpha = {alpha:.3f}")
print("new weights:", w.round(3))
print("weight on the wrong rows:", round(w[wrong].sum(), 3))
Output
alpha = 0.424
new weights: [0.167 0.167 0.167 0.071 0.071 0.071 0.071 0.071 0.071 0.071]
weight on the wrong rows: 0.5

In scikit-learn

python
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import AdaBoostClassifier
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0, stratify=y)

stump = DecisionTreeClassifier(max_depth=1).fit(X_train, y_train)
print(f"one stump         : test accuracy {stump.score(X_test, y_test):.3f}")

for n in [10, 50, 200]:
    ada = AdaBoostClassifier(DecisionTreeClassifier(max_depth=1), n_estimators=n, learning_rate=0.5, random_state=0)
    ada.fit(X_train, y_train)
    print(f"AdaBoost {n:>3} stumps: test accuracy {ada.score(X_test, y_test):.3f}")
Output
one stump         : test accuracy 0.889
AdaBoost  10 stumps: test accuracy 0.942
AdaBoost  50 stumps: test accuracy 0.930
AdaBoost 200 stumps: test accuracy 0.947

One question gets about nine in ten tumours right; a few dozen weighted stumps do much better.

Setting Meaning
estimator The weak learner (default: a stump)
n_estimators Number of boosting rounds
learning_rate Shrinks each stump's say; smaller values need more rounds but often generalise better
Watch Out

Because AdaBoost keeps raising the weight of misclassified rows, mislabelled data and outliers can end up dominating training. If your labels are noisy, gradient boosting with a robust loss, or a random forest, is often safer.

Try It Yourself
  1. Redo the hand calculation for a stump that gets 1 of 10 rows wrong. What is α, and what weight does the wrong row end up with?
  2. Try learning_rate=1.0 and 0.1 with 200 stumps. Which works better on the test set?
The Key Idea

AdaBoost re-weights the rows after each stump so the next one focuses on the mistakes, and gives accurate stumps a bigger vote.

Summary

  • AdaBoost chains stumps; each round re-weights rows towards the mistakes.
  • Amount of say ; wrong rows × , right rows × .
  • The final prediction is a weighted vote.
  • Sensitive to outliers and label noise.
  • Next: a more general form of boosting that fits the errors directly, gradient boosting.