Ensemble Learning

Ensemble Learning combines the predictions of multiple models to produce a result that's typically more accurate and stable than any single model on its own.

The Core Idea

# Instead of relying on one model's prediction,
# combine predictions from several models:

FinalPrediction = Combine(Model1.predict(x), Model2.predict(x), Model3.predict(x), ...)

# Combine could mean majority vote (classification)
# or averaging (regression)

A Simple Example in Python

from sklearn.ensemble import VotingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier

ensemble = VotingClassifier(estimators=[
    ("lr", LogisticRegression()),
    ("dt", DecisionTreeClassifier()),
    ("knn", KNeighborsClassifier())
], voting="hard")

ensemble.fit(X_train, y_train)
print(ensemble.predict(X_test))

Why Ensembles Work

Different models tend to make different mistakes - combining them can average out individual errors, so the ensemble's overall prediction is often more reliable than any one model alone.

Popular ensemble techniques include Bagging (e.g. Random Forest), Boosting (e.g. Gradient Boosting, XGBoost), and Stacking.

Coming Up Next

Next, you'll look at the challenges of standalone models that make ensemble learning so useful.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course