Skip to content

Commit

Permalink
add ch13 and some more notebook tests (rasbt#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt authored Sep 1, 2017
1 parent b56ad60 commit fefb697
Show file tree
Hide file tree
Showing 18 changed files with 1,526 additions and 51,350 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ code/ch12/t10k-labels-idx1-ubyte
code/ch12/train-images-idx3-ubyte
code/ch12/train-labels-idx1-ubyte
code/ch12/mnist_scaled.npz
code/ch13/t10k-images-idx3-ubyte
code/ch13/t10k-labels-idx1-ubyte
code/ch13/train-images-idx3-ubyte
code/ch13/train-labels-idx1-ubyte
docs/equations/*.aux
docs/equations/*.log
docs/equations/*.out
Expand Down
4 changes: 4 additions & 0 deletions .travis/install_travis_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ python -c "import matplotlib; print('matplotlib %s' % matplotlib.__version__)"
python -c "import sklearn; print('sklearn %s' % sklearn.__version__)"
python -c "import pandas; print('pandas %s' % pandas.__version__)"


pip install --upgrade pip

if [ "${COVERAGE}" = "true" ]; then
Expand All @@ -57,3 +58,6 @@ if [ "${LATEST}" = "true" ]; then
else
pip install tensorflow==$TENSORFLOW_VERSION;
fi

python -c "import tensorflow; print('tensorflow %s' % tensorflow.__version__)"

56 changes: 55 additions & 1 deletion code/ch08/ch08.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,41 @@
"B) If you are working with Windows, download an archiver such as [7Zip](http://www.7-zip.org) to extract the files from the download archive."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Optional code to download and unzip the dataset via Python:**"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import tarfile\n",
"\n",
"\n",
"source = 'http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz'\n",
"target = 'aclImdb_v1.tar.gz'\n",
"\n",
"if not os.path.isdir('aclImdb'):\n",
" \n",
" if (sys.version_info < (3, 0)):\n",
" import urllib\n",
" urllib.urlretrieve(source, target)\n",
" \n",
" else:\n",
" import urllib.request\n",
" urllib.request.urlretrieve(source, target)\n",
"\n",
"with tarfile.open(target, 'r:gz') as tar:\n",
" tar.extractall()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -290,7 +325,7 @@
"### Note\n",
"\n",
"If you have problems with creating the `movie_data.csv` file in the previous chapter, you can find a download a zip archive at \n",
"https://github.com/rasbt/python-machine-learning-book-2nd-edition/tree/master/code/ch08/movie_data.csv.zip\n",
"https://github.com/rasbt/python-machine-learning-book-2nd-edition/tree/master/code/ch08/\n",
"<hr>"
]
},
Expand All @@ -302,6 +337,25 @@
"<br>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"## @Readers: PLEASE IGNORE THIS CELL\n",
"##\n",
"## This cell is meant to load a smaller dataset if\n",
"## the notebook is run on the Travis Continuous Integration\n",
"## platform to test the code on a smaller dataset\n",
"## to prevent timeout errors and just serves a debugging tool\n",
"\n",
"if 'TRAVIS' in os.environ:\n",
" df = pd.read_csv('movie_data.csv', nrows=500)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
50,001 changes: 0 additions & 50,001 deletions code/ch08/movie_data.csv

This file was deleted.

Binary file added code/ch08/movie_data.csv.zip
Binary file not shown.
1,310 changes: 0 additions & 1,310 deletions code/ch12/.test_version.ipynb

This file was deleted.

83 changes: 52 additions & 31 deletions code/ch12/ch12.ipynb

Large diffs are not rendered by default.

1,399 changes: 1,399 additions & 0 deletions code/ch13/ch13.ipynb

Large diffs are not rendered by default.

Binary file added code/ch13/images/13_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/ch13/images/13_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/ch13/images/13_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/ch13/images/13_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/ch13/images/13_05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/ch13/t10k-images-idx3-ubyte.gz
Binary file not shown.
Binary file added code/ch13/t10k-labels-idx1-ubyte.gz
Binary file not shown.
Binary file added code/ch13/train-images-idx3-ubyte.gz
Binary file not shown.
Binary file added code/ch13/train-labels-idx1-ubyte.gz
Binary file not shown.
19 changes: 12 additions & 7 deletions code/tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ def test_ch07(self):
run_ipynb(os.path.join(this_dir,
'../ch07/ch07.ipynb'))

# def test_ch08(self):
# this_dir = os.path.dirname(os.path.abspath(__file__))
# run_ipynb(os.path.join(this_dir,
# '../ch08/ch08.ipynb'))
def test_ch08(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch08/ch08.ipynb'))

def test_ch09(self):
this_dir = os.path.dirname(os.path.abspath(__file__))

# run only on Py3, because of the Py3 specific picle files
# run only on Py3, because of the Py3 specific pickle files

if (sys.version_info >= (3, 0)):

Expand All @@ -84,7 +84,7 @@ def test_ch09(self):
run_ipynb(os.path.join(this_dir,
'../ch09/ch09.ipynb'))
except:
print('Unexpected error in Chapter 19:', sys.exc_info()[0])
print('Unexpected error in Chapter 09:', sys.exc_info()[0])
else:
pass

Expand All @@ -102,7 +102,12 @@ def test_ch11(self):
def test_ch12(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch12/.test_version.ipynb'))
'../ch12/ch12.ipynb'))

def test_ch13(self):
this_dir = os.path.dirname(os.path.abspath(__file__))
run_ipynb(os.path.join(this_dir,
'../ch13/ch13.ipynb'))


if __name__ == '__main__':
Expand Down

0 comments on commit fefb697

Please sign in to comment.