File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 2424def movie_norm (xc ):
2525'''Normalize per movie'''
2626xc = 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
3131for 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
3636def learn_for (i ):
@@ -43,12 +43,12 @@ def learn_for(i):
4343eb = 0
4444kf = KFold (len (y ), n_folds = 4 )
4545for 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 ])
5050p = reg .predict (xc ).ravel ()
51- e = (p + x1 ) - y [test ]
51+ e = (p + xpos ) - y [test ]
5252err += np .sum (e * e )
5353eb += np .sum ((y [train ].mean () - y [test ]) ** 2 )
5454return np .sqrt (err / float (len (y ))), np .sqrt (eb / float (len (y )))
You can’t perform that action at this time.
0 commit comments