0% found this document useful (0 votes)
4 views2 pages

EnsembleModels - Ipynb - Colab

The document outlines a Python script using scikit-learn to implement an ensemble model for the Iris dataset. It includes loading the dataset, splitting it into training and testing sets, and creating a Voting Classifier with Logistic Regression, SVC, and Decision Tree models. The final output shows a perfect accuracy score of 1 for the hard voting classifier on the test set.

Uploaded by

Akshay Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

EnsembleModels - Ipynb - Colab

The document outlines a Python script using scikit-learn to implement an ensemble model for the Iris dataset. It includes loading the dataset, splitting it into training and testing sets, and creating a Voting Classifier with Logistic Regression, SVC, and Decision Tree models. The final output shows a perfect accuracy score of 1 for the hard voting classifier on the test set.

Uploaded by

Akshay Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10/21/24, 10:26 AM EnsembleModels.

ipynb - Colab

from sklearn import datasets

# loading iris dataset


iris = datasets.load_iris()
X = [Link][:, :4]
Y = [Link]

from sklearn.model_selection import train_test_split


X_train, X_test, y_train, y_test = train_test_split(X,Y,test_size = 0.20,random_state = 42)

from sklearn.linear_model import LogisticRegression


from [Link] import SVC
from [Link] import DecisionTreeClassifier
from [Link] import VotingClassifier
# Ensemble of Models
estimator = []
[Link](('LR',LogisticRegression(solver ='lbfgs',multi_class ='multinomial',max_iter = 200)
[Link](('SVC', SVC(gamma ='auto', probability = True)))
[Link](('DTC', DecisionTreeClassifier()))

# Voting Classifier with hard voting


hard_voting = VotingClassifier(estimators = estimator, voting ='hard')
hard_voting.fit(X_train, y_train)
y_pred = hard_voting.predict(X_test)

/usr/local/lib/python3.10/dist-packages/sklearn/linear_model/_logistic.py:1247: FutureWarning:
[Link](

# accuracy_score metric to predict Accuracy


from [Link] import accuracy_score
score = accuracy_score(y_test, y_pred)
print("Hard Voting Score % d" % score)

Hard Voting Score 1

[Link] 1/2
10/21/24, 10:26 AM [Link] - Colab

[Link] 2/2

You might also like