Bagging Classifier
A single classifier can be a bit “jumpy”: small changes in the training data can lead it to learn a noticeably different decision boundary. A Bagging Classifier is a practical way to calm that down by averaging many versions of the model.
What it is and how it works
Bagging stands for bootstrap aggregating. The idea is to train many base classifiers independently, each on a slightly different dataset created by bootstrapping (sampling the original training set with replacement). Each model learns its own quirks; then the ensemble combines their predictions. For classification, the most common aggregation is majority vote (or averaging predicted class probabilities and picking the largest).
Why it matters in supervised learning
Bagging mainly reduces variance: it makes predictions more stable and less sensitive to noise in the training set. This is especially valuable for “high-variance” learners like decision trees, which can overfit easily. If you ignore variance reduction, you can end up with a model that looks great on training data but swings wildly on new cases. Bagging usually doesn’t fix strong bias (systematic underfitting); it’s about stabilizing a capable-but-noisy learner.
Practical examples and a concrete API
- Fraud detection: many bootstrapped trees vote, reducing false alarms driven by odd training samples.
- Customer churn: probability averaging gives smoother, better-calibrated churn scores than a single unstable model.
- Medical triage: majority vote can be more robust when labels are noisy.
from sklearn.ensemble import BaggingClassifier
from sklearn.tree import DecisionTreeClassifier
clf = BaggingClassifier(
estimator=DecisionTreeClassifier(),
n_estimators=200,
bootstrap=True,
n_jobs=-1,
random_state=0
)
A Bagging Classifier is an ensemble classifier that trains multiple copies of a base model on different bootstrap-resampled versions of the training set and combines their outputs (typically by majority vote) to produce a final class prediction. It matters because it reduces prediction variance and improves stability and generalization, especially for high-variance learners like decision trees, making performance less sensitive to sampling noise.
Picture a panel of sports referees, each handed a different random selection of replay clips from the same match. Because no two referees watched exactly the same footage, their judgments don’t all go wrong in the same way. When they vote on a close call, the majority verdict is usually fairer than any single referee’s.
A Bagging Classifier works on this principle. It trains many independent models in parallel, each on its own randomly resampled copy of the labeled data, and lets them vote on the category — “fraud” or “not fraud,” say. Because the models are built separately and stumble in different ways, pooling their votes cancels out individual flukes and yields a noticeably steadier classification.