Skip to content

Commit 0dbd6c9

Browse files
author
Ben Cook
committed
reworking incremental_svd2.py
1 parent bca42fc commit 0dbd6c9

11 files changed

+557663
-59096
lines changed

.ipynb_checkpoints/Untitled0-checkpoint.ipynb

+73-1,388
Large diffs are not rendered by default.

data/subset_test.mtx

-56,841
This file was deleted.

incremental_svd2.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def get_error(k,u,train,test):
5858
U,S,V = incremental_SVD(train, k, u, by_row=True)
5959
pred = test_perf(train, test, U,S,V)
6060
ndx = ~np.isnan(pred)
61+
print np.sum(np.isnan(pred))
6162
rmse = np.sqrt(mean_squared_error(pred[ndx], test[ndx,2]))
6263
ortho = np.linalg.norm(U.dot(U.T) - np.identity(U.shape[0]))
6364
return rmse,ortho
@@ -66,22 +67,28 @@ def get_error(k,u,train,test):
6667
train = np.asarray(mmread('subset_train.mtx').todense())
6768
test = np.loadtxt('subset_test.txt', dtype=np.int32)
6869

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)
7077
nums = [100,200,500,1000,2000]
7178

79+
RMSE = np.zeros((len(nums), len(K)))
80+
ORTHO = np.zeros((len(nums), len(K)))
81+
7282

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):
7785
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+
8089

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)
8592

8693

8794

reconstruct_error_200x100.pdf

-16.3 KB
Binary file not shown.

reconstruct_ortho_200x100.pdf

-16.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)