Skip to content

Commit 8386e85

Browse files
committed
ENH Better spacing & comments
1 parent 0999da1 commit 8386e85

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

ch02/chapter.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
elif t == 2:
3030
c = 'b'
3131
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],
3434
marker=marker,
3535
c=c)
3636
# We use NumPy fancy indexing to get an array of strings:
@@ -151,17 +151,15 @@ def is_virginica_test(fi, t, reverse, example):
151151
classifier = KNeighborsClassifier(n_neighbors=1)
152152
classifier = Pipeline([('norm', StandardScaler()), ('knn', classifier)])
153153

154-
155-
156154
means = []
157155
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)
167165
print('Mean accuracy: {:.1%}'.format(np.mean(means)))

0 commit comments

Comments
 (0)