pratham ML
pratham ML
pratham ML
Practical No:01
Aim : On the fruit dataset, compare the performance of Logistic Regression, SVM, KNN on the
basis of
their accuracy.
# Logistic Regression
from sklearn.linear_model import LogisticRegression model = LogisticRegression()
model.fit(X_train, y_train) predictions = model.predict(X_test)
print('Accuracy of Logistic Regression on training set: {:.2f}'.format(model.score(X_train,
y_train))) print('Accuracy of Logistic Regressionr on test set: {:.2f}'.format(model.score(X_test,
y_test))) classification_report(y_test, predictions)
Output :
Prathamesh B Bothe
:- B-235 In-Charge:-Bisweswar Thakur
Name :- Prathamesh B Bothe
RollNo :- B-235 In-Charge:-Bisweswar Thakur
Logistic Regression :
Prathamesh B Bothe
- B-235 In-Charge:-Bisweswar Thakur
Practical No:02
Aim : On the iris dataset, perform KNN algorithm and discuss result
Code :
import pandas as pd
from sklearn.datasets import load_iris iris=load_iris()
iris.feature_names iris.target_names
df= pd.DataFrame(iris.data,columns=iris.feature_names) df.head()
df['target']=iris.target df.head() df[df.target==1].head() df.shape
df['flower_name'] =df.target.apply(lambda x: iris.target_names[x] )
df.head() df0 =df[:50] df1=df[50:100] df2=df[100:]
from sklearn.model_selection import train_test_split
x=df.drop(['target','flower_name'],axis='columns') y=df.target
x_train,x_test,y_train,y_test =train_test_split(x,y,test_size=0.2,random_state=1) len(x_train)
from sklearn.neighbors import KNeighborsClassifier # create knn classifier knn
=KNeighborsClassifier(n_neighbors=10) knn.fit(x_train, y_train)
knn.score(x_test,y_test) from sklearn.metrics import confusion_matrix
y_pred=knn.predict(x_test) cm
= confusion_matrix(y_test,y_pred) cm
%matplotlib inline import matplotlib.pyplot as plt import seaborn as sn
plt.figure(figsize=(7,5)) sn.heatmap(cm, annot=True) plt.xlabel('predicted')
plt.ylabel('True') from sklearn.metrics import classification_report
print(classification_report(y_test,y_pred) Output : feature names :
Target names :
len(x_train) :
Name :- Prathamesh B Bothe
RollNo :- B-235 In-Charge:-Bisweswar Thakur
len(x_test) :
Knn score :
Confusion matrix:
Heatmap:
Classification report :
Name :- Prathamesh B Bothe
RollNo :- B-235 In-Charge:-Bisweswar Thakur
Practical No:03
Aim : Implement apriori algorithm on Online retail dataset and discuss results.
Output :Apriori :
Prathamesh B Bothe
B-235 In-Charge:-Bisweswar Thakur
Practical No:04
Aim : Implement Naïve Bayes Classifier and K-Nearest Neighbor Classifier on Data set of your
choice.Test and Compare for Accuracy and Precision.
Code :
KNN
import numpy as np import pandas as pd
import matplotlib.pyplot as plt
Output : KNN
naïve bayes :
Confusion matrix :
Prathamesh B Bothe
B-235 In-Charge:-Bisweswar Thakur
Practical No:05
Aim : Implement K-Means Clustering on the proper data set of your choice.
Code :
Centroids :
[[1.16666667 1.46666667 1. ]
[7.33333333 9. 0. ]]
Labels : [1 0 1 0 1 0]
Name :- Prathamesh B Bothe
RollNo :- B-235 In-Charge:-Bisweswar Thakur
Practical No:06
Aim : Design and implement SVM for classification with the proper data set of your choice.
Comment on Design and Implementation for Linearly non separable Dataset.
Code :
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_circles from mpl_toolkits.mplot3d import Axes3D
X, Y = make_circles(n_samples = 500, noise = 0.02)
fig = plt.figure()
axes2 = fig.add_subplot(111, projection = '3d') axes2.scatter(X1, X2, X1**2 + X2**2, c = Y,
depthshade = True) axes1 = fig.gca(projection = '3d') axes1.plot_surface(x1, x2, x3, alpha = 0.01)
plt.show() Output:
Prathamesh B Bothe
B-235 In-Charge:-Bisweswar Thakur
Name :- Prathamesh B Bothe
RollNo :- B-235 In-Charge:-Bisweswar Thakur
Practical No:07
# NOT Logic
Function # w = -1, b = 0.5 def
NOT_logicFuncti on(x): w = -1 b = 0.5 return perceptronModel(x, w, b)