|
42 | 42 | "output_type": "stream",
|
43 | 43 | "text": [
|
44 | 44 | "Sebastian Raschka \n",
|
45 |
| - "last updated: 2016-09-29 \n", |
| 45 | + "last updated: 2017-07-29 \n", |
46 | 46 | "\n",
|
47 |
| - "CPython 3.5.2\n", |
48 |
| - "IPython 5.1.0\n", |
| 47 | + "CPython 3.6.1\n", |
| 48 | + "IPython 6.0.0\n", |
49 | 49 | "\n",
|
50 |
| - "numpy 1.11.1\n", |
51 |
| - "scipy 0.18.1\n", |
52 |
| - "matplotlib 1.5.1\n" |
| 50 | + "numpy 1.13.1\n", |
| 51 | + "scipy 0.19.1\n", |
| 52 | + "matplotlib 2.0.2\n" |
53 | 53 | ]
|
54 | 54 | }
|
55 | 55 | ],
|
|
108 | 108 | },
|
109 | 109 | {
|
110 | 110 | "cell_type": "code",
|
111 |
| - "execution_count": 3, |
112 |
| - "metadata": {}, |
| 111 | + "execution_count": 2, |
| 112 | + "metadata": { |
| 113 | + "collapsed": true |
| 114 | + }, |
113 | 115 | "outputs": [],
|
114 | 116 | "source": [
|
115 | 117 | "from IPython.display import Image\n",
|
|
139 | 141 | },
|
140 | 142 | {
|
141 | 143 | "cell_type": "code",
|
142 |
| - "execution_count": 4, |
| 144 | + "execution_count": 3, |
143 | 145 | "metadata": {},
|
144 | 146 | "outputs": [
|
145 | 147 | {
|
|
149 | 151 | "<IPython.core.display.Image object>"
|
150 | 152 | ]
|
151 | 153 | },
|
152 |
| - "execution_count": 4, |
| 154 | + "execution_count": 3, |
153 | 155 | "metadata": {
|
154 | 156 | "image/png": {
|
155 | 157 | "width": 600
|
|
179 | 181 | },
|
180 | 182 | {
|
181 | 183 | "cell_type": "code",
|
182 |
| - "execution_count": 5, |
| 184 | + "execution_count": 4, |
183 | 185 | "metadata": {},
|
184 | 186 | "outputs": [
|
185 | 187 | {
|
|
189 | 191 | "<IPython.core.display.Image object>"
|
190 | 192 | ]
|
191 | 193 | },
|
192 |
| - "execution_count": 5, |
| 194 | + "execution_count": 4, |
193 | 195 | "metadata": {
|
194 | 196 | "image/png": {
|
195 | 197 | "width": 400
|
|
204 | 206 | },
|
205 | 207 | {
|
206 | 208 | "cell_type": "code",
|
207 |
| - "execution_count": 6, |
| 209 | + "execution_count": 5, |
208 | 210 | "metadata": {},
|
209 | 211 | "outputs": [
|
210 | 212 | {
|
|
214 | 216 | "<IPython.core.display.Image object>"
|
215 | 217 | ]
|
216 | 218 | },
|
217 |
| - "execution_count": 6, |
| 219 | + "execution_count": 5, |
218 | 220 | "metadata": {
|
219 | 221 | "image/png": {
|
220 | 222 | "width": 500
|
|
244 | 246 | },
|
245 | 247 | {
|
246 | 248 | "cell_type": "code",
|
247 |
| - "execution_count": 7, |
| 249 | + "execution_count": 6, |
248 | 250 | "metadata": {},
|
249 | 251 | "outputs": [
|
250 | 252 | {
|
|
254 | 256 | "<IPython.core.display.Image object>"
|
255 | 257 | ]
|
256 | 258 | },
|
257 |
| - "execution_count": 7, |
| 259 | + "execution_count": 6, |
258 | 260 | "metadata": {
|
259 | 261 | "image/png": {
|
260 | 262 | "width": 500
|
|
316 | 318 | },
|
317 | 319 | {
|
318 | 320 | "cell_type": "code",
|
319 |
| - "execution_count": 8, |
| 321 | + "execution_count": 7, |
320 | 322 | "metadata": {
|
321 | 323 | "collapsed": true
|
322 | 324 | },
|
|
348 | 350 | " return images, labels"
|
349 | 351 | ]
|
350 | 352 | },
|
| 353 | + { |
| 354 | + "cell_type": "markdown", |
| 355 | + "metadata": {}, |
| 356 | + "source": [ |
| 357 | + "**Important Note**\n", |
| 358 | + "\n", |
| 359 | + "Some readers experienced issues with the `load_mnist` function above as certain decompression tools renamed the files from *-labels-idx1-ubyte* to *-labels.idx1-ubyte*. To avoid this problem altogether, you the modified function above will directly load the dataset from the `gz` archives using Python's `gzip` module." |
| 360 | + ] |
| 361 | + }, |
| 362 | + { |
| 363 | + "cell_type": "code", |
| 364 | + "execution_count": 8, |
| 365 | + "metadata": { |
| 366 | + "collapsed": true |
| 367 | + }, |
| 368 | + "outputs": [], |
| 369 | + "source": [ |
| 370 | + "import os\n", |
| 371 | + "import struct\n", |
| 372 | + "import numpy as np\n", |
| 373 | + "import gzip\n", |
| 374 | + " \n", |
| 375 | + "def load_mnist(path, kind='train'):\n", |
| 376 | + " \"\"\"Load MNIST data from `path`\"\"\"\n", |
| 377 | + " labels_path = os.path.join(path, \n", |
| 378 | + " '%s-labels-idx1-ubyte.gz' % kind)\n", |
| 379 | + " images_path = os.path.join(path, \n", |
| 380 | + " '%s-images-idx3-ubyte.gz' % kind)\n", |
| 381 | + " \n", |
| 382 | + " with gzip.open(labels_path, 'rb') as lbpath:\n", |
| 383 | + " lbpath.read(8)\n", |
| 384 | + " buffer = lbpath.read()\n", |
| 385 | + " labels = np.frombuffer(buffer, dtype=np.uint8)\n", |
| 386 | + "\n", |
| 387 | + " with gzip.open(images_path, 'rb') as imgpath:\n", |
| 388 | + " imgpath.read(16)\n", |
| 389 | + " buffer = imgpath.read()\n", |
| 390 | + " images = np.frombuffer(buffer, \n", |
| 391 | + " dtype=np.uint8).reshape(\n", |
| 392 | + " len(labels), 784).astype(np.float64)\n", |
| 393 | + " \n", |
| 394 | + " return images, labels" |
| 395 | + ] |
| 396 | + }, |
351 | 397 | {
|
352 | 398 | "cell_type": "code",
|
353 | 399 | "execution_count": 9,
|
|
476 | 522 | {
|
477 | 523 | "cell_type": "code",
|
478 | 524 | "execution_count": 13,
|
479 |
| - "metadata": {}, |
| 525 | + "metadata": { |
| 526 | + "collapsed": true |
| 527 | + }, |
480 | 528 | "outputs": [],
|
481 | 529 | "source": [
|
482 | 530 | "# np.savetxt('train_img.csv', X_train, fmt='%i', delimiter=',')\n",
|
|
510 | 558 | {
|
511 | 559 | "cell_type": "code",
|
512 | 560 | "execution_count": 8,
|
513 |
| - "metadata": {}, |
| 561 | + "metadata": { |
| 562 | + "collapsed": true |
| 563 | + }, |
514 | 564 | "outputs": [],
|
515 | 565 | "source": [
|
516 | 566 | "import numpy as np\n",
|
|
921 | 971 | {
|
922 | 972 | "cell_type": "code",
|
923 | 973 | "execution_count": 15,
|
924 |
| - "metadata": {}, |
| 974 | + "metadata": { |
| 975 | + "collapsed": true |
| 976 | + }, |
925 | 977 | "outputs": [],
|
926 | 978 | "source": [
|
927 | 979 | "nn = NeuralNetMLP(n_output=10, \n",
|
|
996 | 1048 | {
|
997 | 1049 | "cell_type": "code",
|
998 | 1050 | "execution_count": 18,
|
999 |
| - "metadata": {}, |
| 1051 | + "metadata": { |
| 1052 | + "collapsed": true |
| 1053 | + }, |
1000 | 1054 | "outputs": [],
|
1001 | 1055 | "source": [
|
1002 | 1056 | "batches = np.array_split(range(len(nn.cost_)), 1000)\n",
|
|
1753 | 1807 | {
|
1754 | 1808 | "cell_type": "code",
|
1755 | 1809 | "execution_count": 29,
|
1756 |
| - "metadata": {}, |
| 1810 | + "metadata": { |
| 1811 | + "collapsed": true |
| 1812 | + }, |
1757 | 1813 | "outputs": [],
|
1758 | 1814 | "source": [
|
1759 | 1815 | "nn_check = MLPGradientCheck(n_output=10, \n",
|
|
2011 | 2067 | "metadata": {
|
2012 | 2068 | "anaconda-cloud": {},
|
2013 | 2069 | "kernelspec": {
|
2014 |
| - "display_name": "Python [default]", |
| 2070 | + "display_name": "Python 3", |
2015 | 2071 | "language": "python",
|
2016 | 2072 | "name": "python3"
|
2017 | 2073 | },
|
|
2025 | 2081 | "name": "python",
|
2026 | 2082 | "nbconvert_exporter": "python",
|
2027 | 2083 | "pygments_lexer": "ipython3",
|
2028 |
| - "version": "3.5.2" |
| 2084 | + "version": "3.6.1" |
2029 | 2085 | }
|
2030 | 2086 | },
|
2031 | 2087 | "nbformat": 4,
|
|
0 commit comments