-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRIS classification.py
More file actions
160 lines (59 loc) · 1.18 KB
/
IRIS classification.py
File metadata and controls
160 lines (59 loc) · 1.18 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import sklearn
# In[2]:
from sklearn.datasets import load_iris
iris = load_iris()
# In[3]:
iris.keys()
# # DESCRIPTION OF DATASET
# In[4]:
print(iris['DESCR'])
# In[5]:
iris['target_names']
# In[6]:
iris['feature_names']
# In[8]:
type(iris['data'])
# In[9]:
iris['data'].shape
# In[10]:
iris['data'][:5]
# In[11]:
iris['target']
# # Training and testing data
# In[14]:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris['data'],iris['target'], random_state = 0)
# In[15]:
X_train.shape
# In[16]:
X_test.shape
# In[17]:
X_test
# In[18]:
y_train.shape
# In[19]:
y_train
# In[20]:
y_test.shape
# # Nearest K neighbor
# In[22]:
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=1)
# In[23]:
knn.fit(X_train, y_train)
# In[25]:
import numpy as np
X_new = np.array([[5, 2.9, 1, 0.2]])
X_new.shape
# In[26]:
prediction = knn.predict(X_new)
prediction
# In[27]:
iris['target_names'][prediction]
# # Evaluating the model
# In[28]:
knn.score(X_test, y_test)
# In[ ]: