bagging and boosting stacking
from sklearn.ensemble import StackingClassifier from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score import warnings warnings.filterwarnings("ignore") # Train a stacking ensemble estimators = [ ('tree', DecisionTreeClassifier(random_state=42)), ('forest', RandomForestClassifier(n_estimators=100, random_state=42)), ('ada', AdaBoostClassifier(base_estimator=DecisionTreeClassifier(max_depth=1), n_estimators=100, random_state=42)) ] stack = StackingClassifier(estimators=estimators, final_estimator=LogisticRegression(random_state=42)) stack.fit(X_train, y_train) # Make predictions stack_pred = stack.predict(X_test) # Calculate accuracy stack_acc = accuracy_score(y_test, stack_pred) print(f"Stacking Accuracy: {stack_acc:.2f}")