|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 6, |
| 5 | + "execution_count": 2, |
6 | 6 | "metadata": {
|
7 | 7 | "collapsed": true
|
8 | 8 | },
|
|
39 | 39 | },
|
40 | 40 | {
|
41 | 41 | "cell_type": "code",
|
42 |
| - "execution_count": 7, |
| 42 | + "execution_count": 3, |
43 | 43 | "metadata": {},
|
44 | 44 | "outputs": [
|
45 | 45 | {
|
|
65 | 65 | },
|
66 | 66 | {
|
67 | 67 | "cell_type": "code",
|
68 |
| - "execution_count": 8, |
| 68 | + "execution_count": 4, |
69 | 69 | "metadata": {},
|
70 | 70 | "outputs": [
|
71 | 71 | {
|
|
111 | 111 | },
|
112 | 112 | {
|
113 | 113 | "cell_type": "code",
|
114 |
| - "execution_count": 9, |
| 114 | + "execution_count": 5, |
115 | 115 | "metadata": {},
|
116 | 116 | "outputs": [],
|
117 | 117 | "source": [
|
|
152 | 152 | },
|
153 | 153 | {
|
154 | 154 | "cell_type": "code",
|
155 |
| - "execution_count": 10, |
| 155 | + "execution_count": 6, |
156 | 156 | "metadata": {},
|
157 | 157 | "outputs": [
|
158 | 158 | {
|
159 | 159 | "name": "stdout",
|
160 | 160 | "output_type": "stream",
|
161 | 161 | "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" |
163 | 163 | ]
|
164 | 164 | }
|
165 | 165 | ],
|
|
200 | 200 | },
|
201 | 201 | {
|
202 | 202 | "cell_type": "code",
|
203 |
| - "execution_count": 11, |
| 203 | + "execution_count": 7, |
204 | 204 | "metadata": {},
|
205 | 205 | "outputs": [
|
206 | 206 | {
|
|
232 | 232 | },
|
233 | 233 | {
|
234 | 234 | "cell_type": "code",
|
235 |
| - "execution_count": 12, |
| 235 | + "execution_count": 8, |
236 | 236 | "metadata": {},
|
237 | 237 | "outputs": [
|
238 | 238 | {
|
|
268 | 268 | },
|
269 | 269 | {
|
270 | 270 | "cell_type": "code",
|
271 |
| - "execution_count": 13, |
| 271 | + "execution_count": 9, |
272 | 272 | "metadata": {},
|
273 | 273 | "outputs": [
|
274 | 274 | {
|
|
308 | 308 | "XX = np.random.randn(num_movies1,num_features1)\n",
|
309 | 309 | "TTheta = np.random.randn(num_users1,num_features1)\n",
|
310 | 310 | "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" |
319 | 312 | ]
|
320 | 313 | },
|
321 | 314 | {
|
322 | 315 | "cell_type": "code",
|
323 |
| - "execution_count": 15, |
| 316 | + "execution_count": 10, |
324 | 317 | "metadata": {},
|
325 | 318 | "outputs": [
|
326 | 319 | {
|
327 | 320 | "name": "stdout",
|
328 | 321 | "output_type": "stream",
|
329 | 322 | "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" |
331 | 324 | ]
|
332 | 325 | }
|
333 | 326 | ],
|
|
366 | 359 | " return g\n",
|
367 | 360 | "\n",
|
368 | 361 | " \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": [ |
370 | 379 | "#get the bestX,bestTheta\n",
|
371 | 380 | "#改变一下参数的shape\n",
|
372 | 381 | "bestX = res[0:num_movies1*num_features1].reshape(num_movies1,num_features1)\n",
|
|
385 | 394 | "favorite = 10\n",
|
386 | 395 | "for i in xrange(favorite):\n",
|
387 | 396 | " 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" |
389 | 400 | ]
|
390 | 401 | },
|
391 | 402 | {
|
392 | 403 | "cell_type": "code",
|
393 | 404 | "execution_count": null,
|
394 | 405 | "metadata": {},
|
395 | 406 | "outputs": [],
|
396 |
| - "source": [ |
397 |
| - "\n", |
398 |
| - "\n" |
399 |
| - ] |
| 407 | + "source": [] |
400 | 408 | }
|
401 | 409 | ],
|
402 | 410 | "metadata": {
|
|
0 commit comments