0% found this document useful (0 votes)
3 views5 pages

Python Classifiers Implementation Guide

The document outlines an experiment to implement various classifiers using Python, including Logistic Regression, KNN, SVM, GaussianNB, Decision Tree, and Random Forest. It includes steps for data preparation, standardization, model training, and evaluation using classification reports. The experiment concludes with a successful implementation of the classifiers.

Uploaded by

Sreelakshmi
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)
3 views5 pages

Python Classifiers Implementation Guide

The document outlines an experiment to implement various classifiers using Python, including Logistic Regression, KNN, SVM, GaussianNB, Decision Tree, and Random Forest. It includes steps for data preparation, standardization, model training, and evaluation using classification reports. The experiment concludes with a successful implementation of the classifiers.

Uploaded by

Sreelakshmi
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

EXPERIMENT NO : 14

AIM : Implement classifiers using python

PROGRAM
Pip install pandas
Import pandas as pd
Pip install scikit-learn
Pip install numpy scikit-learn

# Specify the file path


Path='/home/swlab/Desktop/mufi5/classifier/[Link]’

data=pd.read_csv(path)
X = [Link](columns = 'target', axis = 1)
Y = data['target']

#spliting dataset into training and testdata


from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test =train_test_split(X,Y,test_size = 0.2, random_state = 1)

"""**Standardisation(Also called Z-Distribution Conversion, Normal Distribution Conversion,


Variance Scaling or Mean Removal.)**"""

#Data standardisation
from [Link] import StandardScaler
scaler = StandardScaler()
[Link](X)
X = [Link](X)
#print('X after transform',X)
#X[0]

"""**#1 Logistic Regression**"""

from [Link] import classification_report


from sklearn.linear_model import LogisticRegression

model1 = LogisticRegression(random_state=1) # get instance of model


[Link](x_train, y_train) # Train/Fit model

y_pred1 = [Link](x_test) # get y predictions


print(classification_report(y_test, y_pred1)) # output accuracy

#predict with user input


[Link]([[58,0,0,100,248,0,0,122,0,1,1,0,2]])
OUTPUT :

"""**#2 KNN**"""

from [Link] import classification_report


from [Link] import KNeighborsClassifier

model2 = KNeighborsClassifier() # get instance of model


[Link](x_train, y_train) # Train/Fit model

y_pred2 = [Link](x_test) # get y predictions


print(classification_report(y_test, y_pred2)) # output accuracy

OUTPUT :
"""#3 SVM (Support Vector Machine)"""

from [Link] import classification_report


from [Link] import SVC

model3 = SVC(random_state=1) # get instance of model


[Link](x_train, y_train) # Train/Fit model

y_pred3 = [Link](x_test) # get y predictions


print(classification_report(y_test, y_pred3)) # output accuracy

OUTPUT :

“””#4 GaussianNB”””

from [Link] import classification_report


from sklearn.naive_bayes import GaussianNB

model4 = GaussianNB() # get instance of model


[Link](x_train, y_train) # Train/Fit model

y_pred4 = [Link](x_test) # get y predictions


print(classification_report(y_test, y_pred4)) # output accuracy

OUTPUT :
"""#5 Decision Tree"""

from [Link] import classification_report


from [Link] import DecisionTreeClassifier

model5 = DecisionTreeClassifier(random_state=1) # get instance of model


[Link](x_train, y_train) # Train/Fit model

y_pred5 = [Link](x_test) # get y predictions


print(classification_report(y_test, y_pred5)) # output accuracy

OUTPUT :

"""**#6 Random Forest**"""

from [Link] import RandomForestClassifier

model6 = RandomForestClassifier(random_state=1)# get instance of model


[Link](x_train, y_train) # Train/Fit model

y_pred6 = [Link](x_test) # get y predictions


print(classification_report(y_test, y_pred6)) # output accuracy

OUTPUT :
RESULT : Successfully implement classifiers using python

You might also like