Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen 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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain how stacking differs from other ensemble methods like bagging or boosting?

What are the advantages and disadvantages of using stacking?

Can you suggest scenarios where stacking would be especially beneficial?

bookStacking Ensembles and Meta-Learners

Swipe um das Menü anzuzeigen

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

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2
some-alt