Skip to content

Commit

Permalink
ENH Better spacing & comments
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Jun 16, 2015
1 parent 0999da1 commit 8386e85
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions ch02/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
elif t == 2:
c = 'b'
marker = 'x'
plt.scatter(features[target == t,0],
features[target == t,1],
plt.scatter(features[target == t, 0],
features[target == t, 1],
marker=marker,
c=c)
# We use NumPy fancy indexing to get an array of strings:
Expand Down Expand Up @@ -151,17 +151,15 @@ def is_virginica_test(fi, t, reverse, example):
classifier = KNeighborsClassifier(n_neighbors=1)
classifier = Pipeline([('norm', StandardScaler()), ('knn', classifier)])



means = []
for training,testing in kf:
# We learn a model for this fold with `fit` and then apply it to the
# testing data with `predict`:
classifier.fit(features[training], labels[training])
prediction = classifier.predict(features[testing])

# np.mean on an array of booleans returns fraction
# of correct decisions for this fold:
curmean = np.mean(prediction == labels[testing])
means.append(curmean)
# We learn a model for this fold with `fit` and then apply it to the
# testing data with `predict`:
classifier.fit(features[training], labels[training])
prediction = classifier.predict(features[testing])

# np.mean on an array of booleans returns fraction
# of correct decisions for this fold:
curmean = np.mean(prediction == labels[testing])
means.append(curmean)
print('Mean accuracy: {:.1%}'.format(np.mean(means)))

0 comments on commit 8386e85

Please sign in to comment.