Skip to content

Commit 7fd23a3

Browse files
committed
RFCT Use model as first argument
This makes a slightly smoother transition to using an object
1 parent fa00f07 commit 7fd23a3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ch02/knn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def plurality(xs):
2626
return k
2727

2828
# This function was called ``apply_model`` in the first edition
29-
def predict(features, model):
29+
def predict(model, features):
3030
'''Apply k-nn model'''
3131
k, train_feats, labels = model
3232
results = []
@@ -42,5 +42,5 @@ def predict(features, model):
4242

4343

4444
def accuracy(features, labels, model):
45-
preds = predict(features, model)
45+
preds = predict(model, features)
4646
return np.mean(preds == labels)

ch02/threshold.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def fit_model(features, labels):
4040

4141

4242
# This function was called ``apply_model`` in the first edition
43-
def predict(features, model):
43+
def predict(model, features):
4444
'''Apply a learned model'''
4545
# A model is a pair as returned by fit_model
4646
t, fi, reverse = model
@@ -51,5 +51,5 @@ def predict(features, model):
5151

5252
def accuracy(features, labels, model):
5353
'''Compute the accuracy of the model'''
54-
preds = predict(features, model)
54+
preds = predict(model, features)
5555
return np.mean(preds == labels)

0 commit comments

Comments
 (0)