Professional Documents
Culture Documents
20mid0209 Lab - 6
20mid0209 Lab - 6
20mid0209 Lab - 6
LAB ASSIGNMENT - 6
QUESTION 1:
1) Objective:
The experiment aims to identify the optimal combination of base learners and
meta-learner for stacking. By evaluating different configurations of base
learners and meta-learner parameters, the goal is to discover the ensemble
setup that maximizes the overall accuracy and generalizability of the model.
➢ Load and Split the Data: Load the breast cancer dataset and
split it into training and testing sets, using 80% of the data for
training and 20% for testing.
6) Python code:
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier,
VotingClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Calculate and display mean accuracy scores for individual models and overall
mean accuracy
models = ['Decision Tree', 'Random Forest', 'kNN', 'XGBoost']
model_accuracies = [accuracy for name, accuracy in accuracies] # Assuming
accuracies list is populated
7) Result:
A high accuracy score demonstrates the success of the
Heterogeneous Ensemble Learner in improving the overall
classification performance. It signifies the model's potential to aid in
diagnosing breast cancer, showcasing the strength of combining
diverse algorithms for robust predictions.
Untitled42 - Jupyter Notebook http://localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3
# Create a Logistic Regression model to stack the ensemble's output (modified meta-lea
logistic_regressor = LogisticRegression(C=0.1, random_state=42) # Regularize the Logi
# Train the Logistic Regression model using probabilities from the ensemble
logistic_regressor.fit(ensemble_probs, y_train)
1 of 2 07-11-2023, 19:30
Untitled42 - Jupyter Notebook http://localhost:8888/notebooks/Untitled42.ipynb?kernel_name=python3
In [8]: # Calculate and display mean accuracy scores for individual models and overall mean ac
models = ['Decision Tree', 'Random Forest', 'kNN', 'XGBoost']
model_accuracies = [accuracy for name, accuracy in accuracies] # Assuming accuracies
In [ ]:
2 of 2 07-11-2023, 19:30