Uploaded by luckypurashwani.2

iris classification model

advertisement
10/8/21, 6:50 PM
In [103]:
In [99]:
In [101]:
In [100]:
Out[100]:
In [107]:
iris classification model
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report,confusion_matrix
from sklearn import linear_model
from sklearn.metrics import accuracy_score
iris=datasets.load_iris()
y = iris.target
x1 = iris.data[y>0,0]
x2 = iris.data[y>0,1]
y=y[y>0]
x=np.array([x1,x2])
x=x.T
colors=('r','b','y')
for target in range(1,3):
plt.scatter(x1[y==target],x2[y==target],c=colors[target])
plt.legend([iris.target_names[1],iris.target_names[2]])
plt.xlabel(iris.feature_names[0])
plt.ylabel(iris.feature_names[1])
model=linear_model.LogisticRegression()
model.fit(x,y)
x1p=np.linspace(4.5,8,20)
x2p=-(model.intercept_+model.coef_[0][0]*x1p)/model.coef_[0][1]
plt.plot(x1p,x2p)
plt.ylim(1.5,4.5)
(1.5, 4.5)
yp=model.predict(x)
cm= confusion_matrix(y,yp)
score =accuracy_score(y,yp)
print(score)
cm
localhost:8888/nbconvert/html/iris classification model.ipynb?download=false
1/2
10/8/21, 6:50 PM
iris classification model
0.75
array([[38, 12],
Out[107]:
[13, 37]], dtype=int64)
localhost:8888/nbconvert/html/iris classification model.ipynb?download=false
2/2
Download