Skip to content

Commit 857cbf0

Browse files
committed
MIN Avoid naming variable x1
In certain fonts, it resembles xl too much
1 parent 9916ae4 commit 857cbf0

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎ch07/usermodel.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
def movie_norm(xc):
2525
'''Normalize per movie'''
2626
xc = xc.copy().toarray()
27-
# x1 is the mean of the positive items
28-
x1 = np.array([xi[xi > 0].mean() for xi in xc])
29-
x1 = np.nan_to_num(x1)
27+
# xpos is the mean of the positive items
28+
xpos = np.array([xi[xi > 0].mean() for xi in xc])
29+
xpos = np.nan_to_num(xpos)
3030

3131
for i in range(xc.shape[0]):
32-
xc[i] -= (xc[i] > 0) * x1[i]
33-
return xc, x1
32+
xc[i] -= (xc[i] > 0) * xpos[i]
33+
return xc, xpos
3434

3535

3636
def learn_for(i):
@@ -43,12 +43,12 @@ def learn_for(i):
4343
eb = 0
4444
kf = KFold(len(y), n_folds=4)
4545
for train, test in kf:
46-
xc, x1 = movie_norm(x[train])
47-
reg.fit(xc, y[train] - x1)
46+
xc, xpos = movie_norm(x[train])
47+
reg.fit(xc, y[train] - xpos)
4848

49-
xc, x1 = movie_norm(x[test])
49+
xc, xpos = movie_norm(x[test])
5050
p = reg.predict(xc).ravel()
51-
e = (p + x1) - y[test]
51+
e = (p + xpos) - y[test]
5252
err += np.sum(e * e)
5353
eb += np.sum((y[train].mean() - y[test]) ** 2)
5454
return np.sqrt(err / float(len(y))), np.sqrt(eb / float(len(y)))

0 commit comments

Comments
 (0)