|
29 | 29 | elif t == 2: |
30 | 30 | c = 'b' |
31 | 31 | marker = 'x' |
32 | | - plt.scatter(features[target == t,0], |
33 | | - features[target == t,1], |
| 32 | + plt.scatter(features[target == t, 0], |
| 33 | + features[target == t, 1], |
34 | 34 | marker=marker, |
35 | 35 | c=c) |
36 | 36 | # We use NumPy fancy indexing to get an array of strings: |
@@ -151,17 +151,15 @@ def is_virginica_test(fi, t, reverse, example): |
151 | 151 | classifier = KNeighborsClassifier(n_neighbors=1) |
152 | 152 | classifier = Pipeline([('norm', StandardScaler()), ('knn', classifier)]) |
153 | 153 |
|
154 | | - |
155 | | - |
156 | 154 | means = [] |
157 | 155 | for training,testing in kf: |
158 | | - # We learn a model for this fold with `fit` and then apply it to the |
159 | | - # testing data with `predict`: |
160 | | - classifier.fit(features[training], labels[training]) |
161 | | - prediction = classifier.predict(features[testing]) |
162 | | - |
163 | | - # np.mean on an array of booleans returns fraction |
164 | | - # of correct decisions for this fold: |
165 | | - curmean = np.mean(prediction == labels[testing]) |
166 | | - means.append(curmean) |
| 156 | + # We learn a model for this fold with `fit` and then apply it to the |
| 157 | + # testing data with `predict`: |
| 158 | + classifier.fit(features[training], labels[training]) |
| 159 | + prediction = classifier.predict(features[testing]) |
| 160 | + |
| 161 | + # np.mean on an array of booleans returns fraction |
| 162 | + # of correct decisions for this fold: |
| 163 | + curmean = np.mean(prediction == labels[testing]) |
| 164 | + means.append(curmean) |
167 | 165 | print('Mean accuracy: {:.1%}'.format(np.mean(means))) |
0 commit comments