Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
anushreet
committed
Dec 16, 2016
1 parent
086c438
commit cf27c15
Showing
9 changed files
with
6,777 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 53, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"# create user preferences\n", | ||
"user_pref = np.array([5, 1, 3])\n", | ||
"\n", | ||
"# create a random movie matrix of 10,000 movies\n", | ||
"movies = np.random.randint(5,size=(3,1000))+1\n", | ||
"\n", | ||
"# Note that the randint will make random integers from 0-4\n", | ||
"# so I added a 1 at the end to increase the scale from 1-5" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 54, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"(3,)\n", | ||
"(3, 1000)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print user_pref.shape # (1, 3)\n", | ||
"\n", | ||
"print movies.shape # (3, 1000)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 55, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# np.dot does both dot products and matrix multiplication\n", | ||
"recs = np.dot(user_pref, movies)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 76, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.000160932540894 seconds to run 10000 movies\n", | ||
"0.00121188163757 seconds to run 100000 movies\n", | ||
"0.0105860233307 seconds to run 1000000 movies\n", | ||
"0.096577167511 seconds to run 10000000 movies\n", | ||
"4.16197991371 seconds to run 100000000 movies\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import time\n", | ||
"\n", | ||
"for i in (10000, 100000, 1000000, 10000000, 100000000):\n", | ||
" movies = np.random.randint(5,size=(3,i))+1\n", | ||
" now = time.time()\n", | ||
" np.dot(user_pref, movies)\n", | ||
" print (time.time() - now), \"seconds to run\", i, \"movies\"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 72, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"10.0056350231\n" | ||
] | ||
} | ||
], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.