Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Stacking Ensembles and Meta-Learners | Stacking and Voting Ensembles
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Ensemble Learning Techniques with Python

bookStacking Ensembles and Meta-Learners

Stacking is an advanced ensemble technique where predictions from multiple base models are used as input features for a higher-level model, called a meta-learner. The meta-learner learns how to best combine the base models' outputs to improve overall performance.

Note
Definition

Meta-learner is a model that takes the predictions of base models as input and learns how to combine them for the final prediction.

Note
Definition

Stacking generalization is the process of training a meta-learner on the outputs of base models to generalize better than any single model.

1234567891011121314151617181920212223242526272829303132
from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.ensemble import StackingClassifier from sklearn.tree import DecisionTreeClassifier from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC # Load dataset X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) # Define base models base_estimators = [ ('dt', DecisionTreeClassifier(random_state=42)), ('lr', LogisticRegression(max_iter=1000, random_state=42)), ('svc', SVC(probability=True, random_state=42)) ] # Define meta-learner meta_learner = LogisticRegression(max_iter=1000, random_state=42) # Build stacking ensemble stacking_clf = StackingClassifier( estimators=base_estimators, final_estimator=meta_learner, cv=5 ) # Train and evaluate stacking_clf.fit(X_train, y_train) score = stacking_clf.score(X_test, y_test) print(f"Stacking ensemble accuracy: {score:.2f}")
copy

In the code above, the base models generate predictions that are then used by the meta-learner to make the final decision. This approach can capture patterns that individual models might miss.

question mark

Which statement best describes the role of a meta-learner in a stacking ensemble

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 2

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookStacking Ensembles and Meta-Learners

Glissez pour afficher le menu

Stacking is an advanced ensemble technique where predictions from multiple base models are used as input features for a higher-level model, called a meta-learner. The meta-learner learns how to best combine the base models' outputs to improve overall performance.

Note
Definition

Meta-learner is a model that takes the predictions of base models as input and learns how to combine them for the final prediction.

Note
Definition

Stacking generalization is the process of training a meta-learner on the outputs of base models to generalize better than any single model.

1234567891011121314151617181920212223242526272829303132
from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.ensemble import StackingClassifier from sklearn.tree import DecisionTreeClassifier from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC # Load dataset X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) # Define base models base_estimators = [ ('dt', DecisionTreeClassifier(random_state=42)), ('lr', LogisticRegression(max_iter=1000, random_state=42)), ('svc', SVC(probability=True, random_state=42)) ] # Define meta-learner meta_learner = LogisticRegression(max_iter=1000, random_state=42) # Build stacking ensemble stacking_clf = StackingClassifier( estimators=base_estimators, final_estimator=meta_learner, cv=5 ) # Train and evaluate stacking_clf.fit(X_train, y_train) score = stacking_clf.score(X_test, y_test) print(f"Stacking ensemble accuracy: {score:.2f}")
copy

In the code above, the base models generate predictions that are then used by the meta-learner to make the final decision. This approach can capture patterns that individual models might miss.

question mark

Which statement best describes the role of a meta-learner in a stacking ensemble

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 2
some-alt