-
Notifications
You must be signed in to change notification settings - Fork 2
/
All_CLassification_iris.py
107 lines (69 loc) · 2.05 KB
/
All_CLassification_iris.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 22 17:11:30 2020
@author: shamaun
"""
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
iris = load_iris()
data = iris.data
labels = iris.target
plt.scatter(data[:,0],data[:,1],c=labels)
plt.xlabel('sepal length')
plt.ylabel('sepal width')
plt.show()
plt.scatter(data[:,1],data[:,2],c=labels)
plt.xlabel('sepal width')
plt.ylabel('petal length')
plt.show()
plt.scatter(data[:,2],data[:,3],c=labels)
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.show()
ip = data[:,2:]
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
LR = LogisticRegression()
NB = GaussianNB()
KN = KNeighborsClassifier(n_neighbors=9)
SV = SVC(C=20,kernel='rbf',gamma=50)
LR.fit(ip,labels)
NB.fit(ip,labels)
KN.fit(ip,labels)
SV.fit(ip,labels)
x_min , x_max = ip[:,0].min() , ip[:,0].max()
y_min , y_max = ip[:,1].min() , ip[:,1].max()
xx,yy = np.meshgrid(np.linspace(x_min, x_max),
np.linspace(y_min, y_max))
grid = np.c_[xx.ravel(),yy.ravel()]
predLR = LR.predict(grid).reshape(xx.shape)
predNB = NB.predict(grid).reshape(xx.shape)
predKN = KN.predict(grid).reshape(xx.shape)
predSV = SV.predict(grid).reshape(xx.shape)
plt.contourf(xx,yy,predLR)
plt.scatter(data[:,2],data[:,3],c=labels)
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.title('Logistic Regression')
plt.show()
plt.contourf(xx,yy,predNB)
plt.scatter(data[:,2],data[:,3],c=labels)
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.title('Naive Bayes')
plt.show()
plt.contourf(xx,yy,predKN)
plt.scatter(data[:,2],data[:,3],c=labels)
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.title('KNN')
plt.show()
plt.contourf(xx,yy,predSV)
plt.scatter(data[:,2],data[:,3],c=labels)
plt.xlabel('petal length')
plt.ylabel('petal width')
plt.title('sv')
plt.show()