Skip to content

Commit f7c94f9

Browse files
authored
Add files via upload
1 parent 8efbbef commit f7c94f9

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

Collaborative_Filter.ipynb

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 6,
5+
"execution_count": 2,
66
"metadata": {
77
"collapsed": true
88
},
@@ -39,7 +39,7 @@
3939
},
4040
{
4141
"cell_type": "code",
42-
"execution_count": 7,
42+
"execution_count": 3,
4343
"metadata": {},
4444
"outputs": [
4545
{
@@ -65,7 +65,7 @@
6565
},
6666
{
6767
"cell_type": "code",
68-
"execution_count": 8,
68+
"execution_count": 4,
6969
"metadata": {},
7070
"outputs": [
7171
{
@@ -111,7 +111,7 @@
111111
},
112112
{
113113
"cell_type": "code",
114-
"execution_count": 9,
114+
"execution_count": 5,
115115
"metadata": {},
116116
"outputs": [],
117117
"source": [
@@ -152,14 +152,14 @@
152152
},
153153
{
154154
"cell_type": "code",
155-
"execution_count": 10,
155+
"execution_count": 6,
156156
"metadata": {},
157157
"outputs": [
158158
{
159159
"name": "stdout",
160160
"output_type": "stream",
161161
"text": [
162-
"[[ 3.2694473 0.82260885 0.34742436 3.2694473 0.82260885 0.34742436]\n [ 0.60548622 -5.29818853 -8.71667995 0.60548622 -5.29818853 -8.71667995]\n [ 0.98872539 -5.60773103 -7.1520766 0.98872539 -5.60773103 -7.1520766 ]\n [ 1.27425229 5.80646836 -0.94849499 1.27425229 5.80646836 -0.94849499]]\n[[ -3.21431313 -0.73938093 -0.17662467 -3.21431313 -0.73938093\n -0.17662467]\n [ 1.62875238 -7.84411116 -10.54935153 1.62875238 -7.84411116\n -10.54935153]\n [ 1.04497469 0.56498113 1.51627789 1.04497469 0.56498113\n 1.51627789]\n [ 0.57523149 -0.36704409 0.23436928 0.57523149 -0.36704409\n 0.23436928]\n [ -1.08518528 -3.44655202 -0.38480487 -1.08518528 -3.44655202\n -0.38480487]]\nx max relative error: 5.289068e-10\ntheta max relative error: 2.211348e-10\n"
162+
"[[ -1.4485962 -2.38226893 1.70710777 -1.4485962 -2.38226893\n 1.70710777]\n [ -2.18041855 6.88240991 -7.8848515 -2.18041855 6.88240991\n -7.8848515 ]\n [ 8.23023857 -1.02191424 -4.0025453 8.23023857 -1.02191424\n -4.0025453 ]\n [ 14.13447555 -5.85369614 -5.0379881 14.13447555 -5.85369614\n -5.0379881 ]]\n[[ 0.73826162 2.09184519 -0.48151182 0.73826162 2.09184519\n -0.48151182]\n [ 1.18589767 1.21853183 -1.81195221 1.18589767 1.21853183\n -1.81195221]\n [ -5.30305981 8.71447069 -11.02419571 -5.30305981 8.71447069\n -11.02419571]\n [ 10.43018863 -4.31754416 -6.23177659 10.43018863 -4.31754416\n -6.23177659]\n [ 0.27896481 -1.40228679 1.58240075 0.27896481 -1.40228679\n 1.58240075]]\nx max relative error: 6.712613e-11\ntheta max relative error: 1.661263e-10\n"
163163
]
164164
}
165165
],
@@ -200,7 +200,7 @@
200200
},
201201
{
202202
"cell_type": "code",
203-
"execution_count": 11,
203+
"execution_count": 7,
204204
"metadata": {},
205205
"outputs": [
206206
{
@@ -232,7 +232,7 @@
232232
},
233233
{
234234
"cell_type": "code",
235-
"execution_count": 12,
235+
"execution_count": 8,
236236
"metadata": {},
237237
"outputs": [
238238
{
@@ -268,7 +268,7 @@
268268
},
269269
{
270270
"cell_type": "code",
271-
"execution_count": 13,
271+
"execution_count": 9,
272272
"metadata": {},
273273
"outputs": [
274274
{
@@ -308,26 +308,19 @@
308308
"XX = np.random.randn(num_movies1,num_features1)\n",
309309
"TTheta = np.random.randn(num_users1,num_features1)\n",
310310
"print XX.shape\n",
311-
"print TTheta.shape\n",
312-
"\n",
313-
"\n",
314-
"\n",
315-
"\n",
316-
"\n",
317-
"\n",
318-
"\n"
311+
"print TTheta.shape"
319312
]
320313
},
321314
{
322315
"cell_type": "code",
323-
"execution_count": 15,
316+
"execution_count": 10,
324317
"metadata": {},
325318
"outputs": [
326319
{
327320
"name": "stdout",
328321
"output_type": "stream",
329322
"text": [
330-
"Warning: Maximum number of iterations has been exceeded.\n Current function value: 27848.964019\n Iterations: 100\n Function evaluations: 149\n Gradient evaluations: 149\n(1682L, 10L) (944L, 10L)\n(1682L, 944L)\n[ 4.13867803 3.96850127 4.31376906 3.68773897 3.73023817]\nfavorite 1 score is 5,for:Princess Bride, The (1987) \nfavorite 2 score is 5,for:Star Wars (1977) \nfavorite 3 score is 5,for:Affair to Remember, An (1957) \nfavorite 4 score is 5,for:Entertaining Angels: The Dorothy Day Story (1996) \nfavorite 5 score is 5,for:Great Day in Harlem, A (1994) \nfavorite 6 score is 5,for:Prefontaine (1997) \nfavorite 7 score is 5,for:They Made Me a Criminal (1939) \nfavorite 8 score is 5,for:Santa with Muscles (1996) \nfavorite 9 score is 5,for:Aiqing wansui (1994) \nfavorite 10 score is 5,for:Saint of Fort Washington, The (1993) \n"
323+
"Warning: Maximum number of iterations has been exceeded.\n Current function value: 27696.300753\n Iterations: 100\n Function evaluations: 149\n Gradient evaluations: 149\n"
331324
]
332325
}
333326
],
@@ -366,7 +359,23 @@
366359
" return g\n",
367360
"\n",
368361
" \n",
369-
"res = optimize.fmin_cg(Cost,x0=params,fprime=grad,args=args,maxiter=100)\n",
362+
"res = optimize.fmin_cg(Cost,x0=params,fprime=grad,args=args,maxiter=100)\n"
363+
]
364+
},
365+
{
366+
"cell_type": "code",
367+
"execution_count": 11,
368+
"metadata": {},
369+
"outputs": [
370+
{
371+
"name": "stdout",
372+
"output_type": "stream",
373+
"text": [
374+
"(1682L, 10L) (944L, 10L)\n(1682L, 944L)\n[ 3.83399475 3.34586129 4.46180229 3.76026786 3.44922026]\nfavorite 1 score is 5,for:Return of the Jedi (1983) \nfavorite 2 score is 5,for:Star Wars (1977) \nfavorite 3 score is 5,for:Empire Strikes Back, The (1980) \nfavorite 4 score is 5,for:Independence Day (ID4) (1996) \nfavorite 5 score is 5,for:Renaissance Man (1994) \nfavorite 6 score is 5,for:Star Kid (1997) \nfavorite 7 score is 5,for:Marlene Dietrich: Shadow and Light (1996) \nfavorite 8 score is 5,for:Saint of Fort Washington, The (1993) \nfavorite 9 score is 5,for:Santa with Muscles (1996) \nfavorite 10 score is 5,for:Someone Else's America (1995) \n"
375+
]
376+
}
377+
],
378+
"source": [
370379
"#get the bestX,bestTheta\n",
371380
"#改变一下参数的shape\n",
372381
"bestX = res[0:num_movies1*num_features1].reshape(num_movies1,num_features1)\n",
@@ -385,18 +394,17 @@
385394
"favorite = 10\n",
386395
"for i in xrange(favorite):\n",
387396
" print \"favorite %d score is %d,for:%s\" \\\n",
388-
" %(i+1,my_score[sort_index[-(i+1)]],movieList[sort_index[-(i+1)]])"
397+
" %(i+1,my_score[sort_index[-(i+1)]],movieList[sort_index[-(i+1)]])\n",
398+
" \n",
399+
"\n"
389400
]
390401
},
391402
{
392403
"cell_type": "code",
393404
"execution_count": null,
394405
"metadata": {},
395406
"outputs": [],
396-
"source": [
397-
"\n",
398-
"\n"
399-
]
407+
"source": []
400408
}
401409
],
402410
"metadata": {

0 commit comments

Comments
 (0)