Update installation instructions, and replace 'import numpy' with 'import numpy as np'

main
Aurélien Geron 2016-02-19 11:34:59 +01:00
parent 5fa306c6a0
commit ec681a3174
3 changed files with 46 additions and 49 deletions

View File

@ -14,11 +14,11 @@ Simply open the [Jupyter](http://jupyter.org/) notebooks you are interested in:
# Installation
You will need [git](https://git-scm.com/), obviously.
Obviously, you will need [git](https://git-scm.com/) and [python](https://www.python.org/downloads/) (2 or 3).
First, clone this repository:
$ cd {*your development directory*}
$ cd {your development directory}
$ git clone https://github.com/ageron/ml-notebooks.git
$ cd ml-notebooks
@ -27,15 +27,12 @@ If you want an isolated environment, you can use [virtualenv](https://virtualenv
$ virtualenv env
$ source ./env/bin/activate
Next, install the required python packages using pip:
Next, edit `requirements.txt` to uncomment the right version of TensorFlow for your platform, then install the required python packages using pip:
$ pip install -r requirements.txt # On Linux
OR
$ pip install -r requirements_macosx.txt # On MacOSX
$ pip install -r requirements.txt
Finally, launch Jupyter:
$ jupyter notebook
This should start the Jupyter server locally, and open a browser window. Click on `index.ipynb` to get started.
This should start the Jupyter server locally, and open your browser. Click on `index.ipynb` to get started.

View File

@ -31,7 +31,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
"version": "2.7.11"
}
},
"nbformat": 4,

View File

@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {
"collapsed": false
},
@ -120,7 +120,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's plot a mathematical function. We use numpy's `linspace` function to create an array `x` containing 500 floats ranging from -2 to 2, then we create a second array `y` computed as the square of `x`."
"Now, let's plot a mathematical function. We use NumPy's `linspace` function to create an array `x` containing 500 floats ranging from -2 to 2, then we create a second array `y` computed as the square of `x` (to learn about NumPy, read the [NumPy tutorial](tools_numpy.ipynb))."
]
},
{
@ -131,8 +131,8 @@
},
"outputs": [],
"source": [
"import numpy\n",
"x = numpy.linspace(-2, 2, 500)\n",
"import numpy as np\n",
"x = np.linspace(-2, 2, 500)\n",
"y = x**2\n",
"\n",
"plt.plot(x, y)\n",
@ -269,7 +269,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.4, 1.4, 30)\n",
"x = np.linspace(-1.4, 1.4, 30)\n",
"plt.plot(x, x, 'g--', x, x**2, 'r:', x, x**3, 'b^')\n",
"plt.show()"
]
@ -290,7 +290,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.4, 1.4, 30)\n",
"x = np.linspace(-1.4, 1.4, 30)\n",
"line1, line2, line3 = plt.plot(x, x, 'g--', x, x**2, 'r:', x, x**3, 'b^')\n",
"line1.set_linewidth(3.0)\n",
"line1.set_dash_capstyle(\"round\")\n",
@ -315,7 +315,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.4, 1.4, 30)\n",
"x = np.linspace(-1.4, 1.4, 30)\n",
"plt.plot(x, x**2)\n",
"plt.savefig(\"my_square_function.png\", transparent=True)"
]
@ -337,7 +337,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.4, 1.4, 30)\n",
"x = np.linspace(-1.4, 1.4, 30)\n",
"plt.subplot(2, 2, 1) # 2 rows, 2 columns, 1st subplot = top left\n",
"plt.plot(x, x)\n",
"plt.subplot(2, 2, 2) # 2 rows, 2 columns, 2nd subplot = top right\n",
@ -430,7 +430,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.4, 1.4, 30)\n",
"x = np.linspace(-1.4, 1.4, 30)\n",
"\n",
"plt.figure(1)\n",
"plt.subplot(211)\n",
@ -490,11 +490,11 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-2, 2, 200)\n",
"x = np.linspace(-2, 2, 200)\n",
"fig1, (ax_top, ax_bottom) = plt.subplots(2, 1, sharex=True)\n",
"fig1.set_size_inches(10,5)\n",
"line1, line2 = ax_top.plot(x, numpy.sin(3*x**2), \"r-\", x, numpy.cos(5*x**2), \"b-\")\n",
"line3, = ax_bottom.plot(x, numpy.sin(3*x), \"r-\")\n",
"line1, line2 = ax_top.plot(x, np.sin(3*x**2), \"r-\", x, np.cos(5*x**2), \"b-\")\n",
"line3, = ax_bottom.plot(x, np.sin(3*x), \"r-\")\n",
"ax_top.grid(True)\n",
"\n",
"fig2, ax = plt.subplots(1, 1)\n",
@ -514,7 +514,7 @@
"\n",
"Pyplot provides a number of tools to plot graphs, including the state-machine interface to the underlying object-oriented plotting library.\n",
"\n",
"Pylab is a convenience module that imports matplotlib.pyplot and numpy in a single name space. You will find many examples using pylab, but it is no longer recommended (because *explicit* imports are better than *implicit* ones)."
"Pylab is a convenience module that imports matplotlib.pyplot and NumPy in a single name space. You will find many examples using pylab, but it is no longer recommended (because *explicit* imports are better than *implicit* ones)."
]
},
{
@ -533,7 +533,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.5, 1.5, 30)\n",
"x = np.linspace(-1.5, 1.5, 30)\n",
"px = 0.8\n",
"py = px**2\n",
"\n",
@ -642,7 +642,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1.4, 1.4, 50)\n",
"x = np.linspace(-1.4, 1.4, 50)\n",
"plt.plot(x, x**2, \"r--\", label=\"Square function\")\n",
"plt.plot(x, x**3, \"g-\", label=\"Cube function\")\n",
"plt.legend(loc=\"best\")\n",
@ -667,8 +667,8 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(0.1, 15, 500)\n",
"y = x**3/numpy.exp(2*x)\n",
"x = np.linspace(0.1, 15, 500)\n",
"y = x**3/np.exp(2*x)\n",
"\n",
"plt.figure(1)\n",
"plt.plot(x, y)\n",
@ -716,7 +716,7 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-2, 2, 100)\n",
"x = np.linspace(-2, 2, 100)\n",
"\n",
"plt.figure(1, figsize=(15,10))\n",
"plt.subplot(131)\n",
@ -726,7 +726,7 @@
"\n",
"ax = plt.subplot(132)\n",
"plt.plot(x, x**3)\n",
"ax.xaxis.set_ticks(numpy.arange(-2, 2, 1))\n",
"ax.xaxis.set_ticks(np.arange(-2, 2, 1))\n",
"plt.grid(True)\n",
"plt.title(\"Manual ticks on the x-axis\")\n",
"\n",
@ -735,7 +735,7 @@
"plt.minorticks_on()\n",
"ax.tick_params(axis='x', which='minor', bottom='off')\n",
"ax.xaxis.set_ticks([-2, 0, 1, 2])\n",
"ax.yaxis.set_ticks(numpy.arange(-5, 5, 1))\n",
"ax.yaxis.set_ticks(np.arange(-5, 5, 1))\n",
"ax.yaxis.set_ticklabels([\"min\", -4, -3, -2, -1, 0, 1, 2, 3, \"max\"])\n",
"plt.title(\"Manual ticks and tick labels\\n(plus minor ticks) on the y-axis\")\n",
"\n",
@ -762,11 +762,11 @@
"outputs": [],
"source": [
"radius = 1\n",
"theta = numpy.linspace(0, 2*numpy.pi*radius, 1000)\n",
"theta = np.linspace(0, 2*np.pi*radius, 1000)\n",
"\n",
"plt.subplot(111, projection='polar')\n",
"plt.plot(theta, numpy.sin(5*theta), \"g-\")\n",
"plt.plot(theta, 0.5*numpy.cos(20*theta), \"b-\")\n",
"plt.plot(theta, np.sin(5*theta), \"g-\")\n",
"plt.plot(theta, 0.5*np.cos(20*theta), \"b-\")\n",
"plt.show()"
]
},
@ -790,11 +790,11 @@
"source": [
"from mpl_toolkits.mplot3d import Axes3D\n",
"\n",
"x = numpy.linspace(-5, 5, 50)\n",
"y = numpy.linspace(-5, 5, 50)\n",
"X, Y = numpy.meshgrid(x, y)\n",
"R = numpy.sqrt(X**2 + Y**2)\n",
"Z = numpy.sin(R)\n",
"x = np.linspace(-5, 5, 50)\n",
"y = np.linspace(-5, 5, 50)\n",
"X, Y = np.meshgrid(x, y)\n",
"R = np.sqrt(X**2 + Y**2)\n",
"Z = np.sin(R)\n",
"\n",
"figure = plt.figure(1, figsize = (12, 4))\n",
"subplot3d = plt.subplot(111, projection='3d')\n",
@ -969,11 +969,11 @@
},
"outputs": [],
"source": [
"data1 = numpy.random.randn(400)\n",
"data2 = numpy.random.randn(500) + 3\n",
"data3 = numpy.random.randn(450) + 6\n",
"data4a = numpy.random.randn(200) + 9\n",
"data4b = numpy.random.randn(100) + 10\n",
"data1 = np.random.randn(400)\n",
"data2 = np.random.randn(500) + 3\n",
"data3 = np.random.randn(450) + 6\n",
"data4a = np.random.randn(200) + 9\n",
"data4b = np.random.randn(100) + 10\n",
"\n",
"plt.hist(data1, bins=5, color='g', alpha=0.75, label='bar hist') # default histtype='bar'\n",
"plt.hist(data2, color='b', alpha=0.65, histtype='stepfilled', label='stepfilled hist')\n",
@ -1065,7 +1065,7 @@
},
"outputs": [],
"source": [
"img = numpy.arange(100*100).reshape(100, 100)\n",
"img = np.arange(100*100).reshape(100, 100)\n",
"print img\n",
"plt.imshow(img)\n",
"plt.show()"
@ -1107,7 +1107,7 @@
},
"outputs": [],
"source": [
"img = numpy.empty((20,30,3))\n",
"img = np.empty((20,30,3))\n",
"img[:, :10] = [0, 0, 0.6]\n",
"img[:, 10:20] = [1, 1, 1]\n",
"img[:, 20:] = [0.6, 0, 0]\n",
@ -1175,9 +1175,9 @@
},
"outputs": [],
"source": [
"x = numpy.linspace(-1, 1, 100)\n",
"y = numpy.sin(x**2*25)\n",
"data = numpy.array([x, y])\n",
"x = np.linspace(-1, 1, 100)\n",
"y = np.sin(x**2*25)\n",
"data = np.array([x, y])\n",
"\n",
"fig = plt.figure()\n",
"line, = plt.plot([], [], \"r-\") # start with an empty plot\n",
@ -1188,7 +1188,7 @@
"\n",
"# this function will be called at every iteration\n",
"def update_line(num, data, line):\n",
" line.set_data(data[..., :num] + numpy.random.rand(2, num) / 25) # we only plot the first `num` data points.\n",
" line.set_data(data[..., :num] + np.random.rand(2, num) / 25) # we only plot the first `num` data points.\n",
" return line,\n",
"\n",
"line_ani = animation.FuncAnimation(fig, update_line, frames=100, fargs=(data, line), interval=67)\n",
@ -1241,7 +1241,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
"version": "2.7.11"
}
},
"nbformat": 4,