Skip to content

Commit

Permalink
Updated files
Browse files Browse the repository at this point in the history
  • Loading branch information
anushreet committed Dec 16, 2016
1 parent 086c438 commit cf27c15
Show file tree
Hide file tree
Showing 9 changed files with 6,777 additions and 0 deletions.
2,412 changes: 2,412 additions & 0 deletions Code/chapter_1.ipynb

Large diffs are not rendered by default.

617 changes: 617 additions & 0 deletions Code/chapter_10.ipynb

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions Code/chapter_4.ipynb
@@ -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
}
351 changes: 351 additions & 0 deletions Code/chapter_5.ipynb

Large diffs are not rendered by default.

0 comments on commit cf27c15

Please sign in to comment.