Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AdaBoostClassifier / AdaBoostRegressor

API Reference

Signature

clf = sp.AdaBoostClassifier(
    n_estimators=50, learning_rate=1.0
)
reg = sp.AdaBoostRegressor(
    n_estimators=50, learning_rate=1.0
)

model.fit(X, y)
model.predict(X)               -> list[int] | list[float]
model.predict_proba(X)         -> ndarray (n, K)   # classifier only
model.score(X, y)              -> float
model.get_params()             -> dict
model.set_params(n_estimators=..., learning_rate=...)

Constructor parameters

ParameterTypeDefaultDescription
n_estimatorsint50Maximum number of weak learners
learning_ratefloat1.0Shrinkage applied to each weak learner's contribution

Attributes

AttributeTypeDescription
classes_list[int]Unique class labels (classifier only)
estimator_weights_list[float]Weight $\alpha_m$ assigned to each weak learner
estimator_errors_list[float]Weighted error of each weak learner
Example
import seraplot as sp
import numpy as np

X = np.random.randn(300, 4)
y = np.sign(X[:, 0] * X[:, 1]).astype(int)

clf = sp.AdaBoostClassifier(n_estimators=100, learning_rate=0.5)
clf.fit(X, y)
print(f"Accuracy: {clf.score(X, y):.4f}")

Algorithmic Functioning

AdaBoost (Adaptive Boosting) builds a weighted sum of weak classifiers by iteratively re-weighting misclassified samples.

Initialisation — uniform sample weights:

$$w_i^{(1)} = \frac{1}{n}, \quad i = 1, \ldots, n$$

Boosting iteration $m = 1, \ldots, M$:

1. Fit a weak learner $h_m$ to the weighted dataset.

2. Compute the weighted error:

$$\varepsilon_m = \sum_{i=1}^n w_i^{(m)} \cdot \mathbf{1}\bigl[h_m(x_i) \neq y_i\bigr]$$

3. Compute the learner weight (contribution of $h_m$):

$$\alpha_m = \nu \cdot \frac{1}{2}\ln\!\left(\frac{1 - \varepsilon_m}{\varepsilon_m}\right)$$

where $\nu$ is the learning_rate. A perfect classifier ($\varepsilon_m = 0$) receives $\alpha_m \to \infty$; a random guesser ($\varepsilon_m = 0.5$) receives $\alpha_m = 0$.

4. Update and renormalise sample weights, down-weighting correctly classified samples:

$$w_i^{(m+1)} \propto w_i^{(m)} \exp\!\bigl(-\alpha_m y_i h_m(x_i)\bigr)$$

Final classifier — weighted majority vote:

$$F(x) = \text{sign}\!\left(\sum_{m=1}^M \alpha_m h_m(x)\right)$$

Regressor (AdaBoost.R2) — weak learners are fitted to the residuals weighted by a loss-based sample reweighting scheme, and the ensemble prediction is the weighted median.

Stopping condition: if $\varepsilon_m \geq 0.5$, the iteration is stopped early (the current learner is no better than random).

Référence API

Signature

clf = sp.AdaBoostClassifier(
    n_estimators=50, learning_rate=1.0
)
reg = sp.AdaBoostRegressor(
    n_estimators=50, learning_rate=1.0
)

model.fit(X, y)
model.predict(X)               -> list[int] | list[float]
model.predict_proba(X)         -> ndarray (n, K)   # classificateur seulement
model.score(X, y)              -> float
model.get_params()             -> dict
model.set_params(n_estimators=..., learning_rate=...)

Paramètres du constructeur

ParamètreTypeDéfautDescription
n_estimatorsint50Nombre maximum d'apprenants faibles
learning_ratefloat1.0Rétrécissement appliqué à la contribution de chaque apprenant faible

Attributs

AttributTypeDescription
classes_list[int]Labels de classes uniques (classificateur seulement)
estimator_weights_list[float]Poids $\alpha_m$ attribué à chaque apprenant faible
estimator_errors_list[float]Erreur pondérée de chaque apprenant faible
Exemple
import seraplot as sp
import numpy as np

X = np.random.randn(300, 4)
y = np.sign(X[:, 0] * X[:, 1]).astype(int)

clf = sp.AdaBoostClassifier(n_estimators=100, learning_rate=0.5)
clf.fit(X, y)
print(f"Précision : {clf.score(X, y):.4f}")

Fonctionnement algorithmique

AdaBoost (Adaptive Boosting) construit une somme pondérée de classificateurs faibles en ré-pondérant itérativement les échantillons mal classifiés.

Initialisation — poids d'échantillons uniformes :

$$w_i^{(1)} = \frac{1}{n}, \quad i = 1, \ldots, n$$

Itération de boosting $m = 1, \ldots, M$ :

1. Ajuster un apprenant faible $h_m$ au jeu de données pondéré.

2. Calculer l'erreur pondérée :

$$\varepsilon_m = \sum_{i=1}^n w_i^{(m)} \cdot \mathbf{1}\bigl[h_m(x_i) \neq y_i\bigr]$$

3. Calculer le poids de l'apprenant (contribution de $h_m$) :

$$\alpha_m = \nu \cdot \frac{1}{2}\ln\!\left(\frac{1 - \varepsilon_m}{\varepsilon_m}\right)$$

où $\nu$ est le learning_rate. Un classificateur parfait ($\varepsilon_m = 0$) reçoit $\alpha_m \to \infty$ ; un devineur aléatoire ($\varepsilon_m = 0,5$) reçoit $\alpha_m = 0$.

4. Mettre à jour et renormaliser les poids des échantillons, en réduisant le poids des échantillons correctement classifiés :

$$w_i^{(m+1)} \propto w_i^{(m)} \exp\!\bigl(-\alpha_m y_i h_m(x_i)\bigr)$$

Classificateur final — vote majoritaire pondéré :

$$F(x) = \text{sign}\!\left(\sum_{m=1}^M \alpha_m h_m(x)\right)$$

Régresseur (AdaBoost.R2) — les apprenants faibles sont ajustés aux résidus pondérés par un schéma de ré-pondération basé sur la perte, et la prédiction de l'ensemble est la médiane pondérée.

Condition d'arrêt : si $\varepsilon_m \geq 0,5$, l'itération s'arrête prématurément (l'apprenant courant n'est pas meilleur qu'aléatoire).