File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ regression.py
25
25
stacked.py
26
26
Stacked predictions
27
27
averaged.py
28
- Averaging of predictions
28
+ Averaging of predictions (mentioned in book, but code is not shown there).
29
29
30
30
Association Rule Mining
31
31
-----------------------
Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+ import load_ml100k
3
+ import regression
4
+ import corrneighbours
5
+ from sklearn import metrics
6
+ import norm
7
+
8
+ def predict (train ):
9
+ predicted0 = regression .predict (train )
10
+ predicted1 = regression .predict (train .T ).T
11
+ predicted2 = corrneighbours .predict (train )
12
+ predicted3 = corrneighbours .predict (train .T ).T
13
+ predicted4 = norm .predict (train )
14
+ predicted5 = norm .predict (train .T ).T
15
+ stack = np .array ([
16
+ predicted0 ,
17
+ predicted1 ,
18
+ predicted2 ,
19
+ predicted3 ,
20
+ predicted4 ,
21
+ predicted5 ,
22
+ ])
23
+ return stack .mean (0 )
24
+
25
+
26
+ def main ():
27
+ train ,test = load_ml100k .get_train_test (random_state = 12 )
28
+ predicted = predict (train )
29
+ r2 = metrics .r2_score (test [test > 0 ], predicted [test > 0 ])
30
+ print ('R2 averaged: {:.2%}' .format (r2 ))
31
+
32
+ if __name__ == '__main__' :
33
+ main ()
You can’t perform that action at this time.
0 commit comments