@@ -58,6 +58,7 @@ def get_error(k,u,train,test):
58
58
U ,S ,V = incremental_SVD (train , k , u , by_row = True )
59
59
pred = test_perf (train , test , U ,S ,V )
60
60
ndx = ~ np .isnan (pred )
61
+ print np .sum (np .isnan (pred ))
61
62
rmse = np .sqrt (mean_squared_error (pred [ndx ], test [ndx ,2 ]))
62
63
ortho = np .linalg .norm (U .dot (U .T ) - np .identity (U .shape [0 ]))
63
64
return rmse ,ortho
@@ -66,22 +67,28 @@ def get_error(k,u,train,test):
66
67
train = np .asarray (mmread ('subset_train.mtx' ).todense ())
67
68
test = np .loadtxt ('subset_test.txt' , dtype = np .int32 )
68
69
69
- K = range (5 ,35 )
70
+ num = 0
71
+ for i in xrange (train .shape [0 ]):
72
+ if np .all (train [i ,:] == 0 ):
73
+ num += 1
74
+ print 'all zeros' , num
75
+
76
+ K = range (3 ,15 )
70
77
nums = [100 ,200 ,500 ,1000 ,2000 ]
71
78
79
+ RMSE = np .zeros ((len (nums ), len (K )))
80
+ ORTHO = np .zeros ((len (nums ), len (K )))
81
+
72
82
73
- for u in nums :
74
- RMSE = []
75
- ORTHO = []
76
- for k in K :
83
+ for i ,u in enumerate (nums ):
84
+ for j ,k in enumerate (K ):
77
85
rmse ,ortho = get_error (k ,u ,train ,test )
78
- RMSE .append (rmse )
79
- ORTHO .append (ortho )
86
+ RMSE [i ,j ] = rmse
87
+ ORTHO [i ,j ] = ortho
88
+
80
89
81
- plt .plot (K ,RMSE )
82
- plt .show ()
83
- plt .plot (K ,ORTHO )
84
- plt .show ()
90
+ np .savetxt ('RMSE.txt' , RMSE )
91
+ np .savetxt ('ORTHO.txt' , ORTHO )
85
92
86
93
87
94
0 commit comments