Ensemble Learning Concept with Few Lines of Code and 95% Accuracy πŸ”₯

Loading dataset

import pandas as pd
data=pd.read_csv('../input/seed-from-uci/Seed_Data.csv')
X=data.drop('target',axis=1)
y=data['target']

Dataset splitting into training and testing

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y, test_size=0.3,random_state=3)

We call the algorithms like this way

from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import LinearSVC
from sklearn.tree import DecisionTreeClassifier
knn=KNeighborsClassifier()
nab=GaussianNB()
svc=LinearSVC()
dt=DecisionTreeClassifier()

Then we use Voting Classifier for ensemble learning

from sklearn.ensemble import VotingClassifier
Ens = VotingClassifier( estimators= [('KNN',knn),('NB',nab),('SVM',svc),('DT',dt)], voting = 'hard')

Training the Ensemble learning

Ens= Ens.fit(X_train , y_train)

Accuracy of Ensemble learning

print('Accuracy score of Ensemble Learning is = {:.2f}'.format(Ens.score(X_test, y_test)),'%')

Do you want to run the code with the dataset?

Visit here https://www.kaggle.com/imranzaman5202/ensemble-learning-few-line-95-accuracy

--

--