Skip to content

    Ensemble Learning (Bagging, Voting, Stacking)

    Machine Learning · Intermediate

    Definition

    Ensembles combine several models so their errors cancel out.

    Usually more accurate and robust than any single model.

    Diagram

    Model AModel BModel C→ vote

    Flowchart

    Train multiple modelsCombine by vote/averageOr train a meta-model (stacking)

    Example: Majority vote

    preds = ['spam', 'ham', 'spam']
    print(max(set(preds), key=preds.count))

    Output: spam

    Key points

    • Random forest = bagging of trees
    • Diverse models ensemble best

    Interview questions

    Why do ensembles help?

    Independent errors average out, reducing variance.

    More Machine Learning topics