Skip to content

Commit 016dc1a

Browse files
committed
update tests
1 parent 7c0f81f commit 016dc1a

File tree

4 files changed

+239
-63
lines changed

4 files changed

+239
-63
lines changed

.travis/install_travis_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ else
6060
fi
6161

6262
python -c "import tensorflow; print('tensorflow %s' % tensorflow.__version__)"
63+
python -c "import os; print(os.environ)"
6364

code/ch08/ch08.ipynb

Lines changed: 95 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
},
149149
{
150150
"cell_type": "code",
151-
"execution_count": 5,
151+
"execution_count": 22,
152152
"metadata": {
153153
"collapsed": true
154154
},
@@ -185,16 +185,15 @@
185185
},
186186
{
187187
"cell_type": "code",
188-
"execution_count": 2,
188+
"execution_count": 23,
189189
"metadata": {},
190190
"outputs": [
191191
{
192192
"name": "stderr",
193193
"output_type": "stream",
194194
"text": [
195-
"0% 100%\n",
196-
"[##############################] | ETA: 00:00:00\n",
197-
"Total time elapsed: 00:01:28\n"
195+
"0% [##############################] 100% | ETA: 00:00:00\n",
196+
"Total time elapsed: 00:02:21\n"
198197
]
199198
}
200199
],
@@ -233,7 +232,7 @@
233232
},
234233
{
235234
"cell_type": "code",
236-
"execution_count": 3,
235+
"execution_count": 24,
237236
"metadata": {
238237
"collapsed": true
239238
},
@@ -254,7 +253,7 @@
254253
},
255254
{
256255
"cell_type": "code",
257-
"execution_count": 4,
256+
"execution_count": 25,
258257
"metadata": {
259258
"collapsed": true
260259
},
@@ -265,13 +264,26 @@
265264
},
266265
{
267266
"cell_type": "code",
268-
"execution_count": 5,
267+
"execution_count": 26,
269268
"metadata": {},
270269
"outputs": [
271270
{
272271
"data": {
273272
"text/html": [
274273
"<div>\n",
274+
"<style>\n",
275+
" .dataframe thead tr:only-child th {\n",
276+
" text-align: right;\n",
277+
" }\n",
278+
"\n",
279+
" .dataframe thead th {\n",
280+
" text-align: left;\n",
281+
" }\n",
282+
"\n",
283+
" .dataframe tbody tr th {\n",
284+
" vertical-align: top;\n",
285+
" }\n",
286+
"</style>\n",
275287
"<table border=\"1\" class=\"dataframe\">\n",
276288
" <thead>\n",
277289
" <tr style=\"text-align: right;\">\n",
@@ -283,17 +295,17 @@
283295
" <tbody>\n",
284296
" <tr>\n",
285297
" <th>0</th>\n",
286-
" <td>\"Two Hands\" is a good addition to the Australi...</td>\n",
298+
" <td>In 1974, the teenager Martha Moxley (Maggie Gr...</td>\n",
287299
" <td>1</td>\n",
288300
" </tr>\n",
289301
" <tr>\n",
290302
" <th>1</th>\n",
291-
" <td>It's New Year's eve, a cop-killer (in the form...</td>\n",
303+
" <td>OK... so... I really like Kris Kristofferson a...</td>\n",
292304
" <td>0</td>\n",
293305
" </tr>\n",
294306
" <tr>\n",
295307
" <th>2</th>\n",
296-
" <td>I figured that any horror film with Orson Well...</td>\n",
308+
" <td>***SPOILER*** Do not read this, if you think a...</td>\n",
297309
" <td>0</td>\n",
298310
" </tr>\n",
299311
" </tbody>\n",
@@ -302,12 +314,12 @@
302314
],
303315
"text/plain": [
304316
" review sentiment\n",
305-
"0 \"Two Hands\" is a good addition to the Australi... 1\n",
306-
"1 It's New Year's eve, a cop-killer (in the form... 0\n",
307-
"2 I figured that any horror film with Orson Well... 0"
317+
"0 In 1974, the teenager Martha Moxley (Maggie Gr... 1\n",
318+
"1 OK... so... I really like Kris Kristofferson a... 0\n",
319+
"2 ***SPOILER*** Do not read this, if you think a... 0"
308320
]
309321
},
310-
"execution_count": 5,
322+
"execution_count": 26,
311323
"metadata": {},
312324
"output_type": "execute_result"
313325
}
@@ -788,7 +800,7 @@
788800
},
789801
{
790802
"cell_type": "code",
791-
"execution_count": 19,
803+
"execution_count": 9,
792804
"metadata": {
793805
"collapsed": true
794806
},
@@ -808,7 +820,7 @@
808820
},
809821
{
810822
"cell_type": "code",
811-
"execution_count": 20,
823+
"execution_count": 10,
812824
"metadata": {},
813825
"outputs": [
814826
{
@@ -817,7 +829,7 @@
817829
"['runners', 'like', 'running', 'and', 'thus', 'they', 'run']"
818830
]
819831
},
820-
"execution_count": 20,
832+
"execution_count": 10,
821833
"metadata": {},
822834
"output_type": "execute_result"
823835
}
@@ -828,7 +840,7 @@
828840
},
829841
{
830842
"cell_type": "code",
831-
"execution_count": 21,
843+
"execution_count": 11,
832844
"metadata": {},
833845
"outputs": [
834846
{
@@ -837,7 +849,7 @@
837849
"['runner', 'like', 'run', 'and', 'thu', 'they', 'run']"
838850
]
839851
},
840-
"execution_count": 21,
852+
"execution_count": 11,
841853
"metadata": {},
842854
"output_type": "execute_result"
843855
}
@@ -848,14 +860,15 @@
848860
},
849861
{
850862
"cell_type": "code",
851-
"execution_count": 22,
863+
"execution_count": 12,
852864
"metadata": {},
853865
"outputs": [
854866
{
855867
"name": "stdout",
856868
"output_type": "stream",
857869
"text": [
858-
"[nltk_data] Downloading package stopwords to /home/ubuntu/nltk_data...\n",
870+
"[nltk_data] Downloading package stopwords to\n",
871+
"[nltk_data] /Users/sebastian/nltk_data...\n",
859872
"[nltk_data] Package stopwords is already up-to-date!\n"
860873
]
861874
},
@@ -865,7 +878,7 @@
865878
"True"
866879
]
867880
},
868-
"execution_count": 22,
881+
"execution_count": 12,
869882
"metadata": {},
870883
"output_type": "execute_result"
871884
}
@@ -878,7 +891,7 @@
878891
},
879892
{
880893
"cell_type": "code",
881-
"execution_count": 23,
894+
"execution_count": 13,
882895
"metadata": {},
883896
"outputs": [
884897
{
@@ -887,7 +900,7 @@
887900
"['runner', 'like', 'run', 'run', 'lot']"
888901
]
889902
},
890-
"execution_count": 23,
903+
"execution_count": 13,
891904
"metadata": {},
892905
"output_type": "execute_result"
893906
}
@@ -981,9 +994,32 @@
981994
"cell_type": "markdown",
982995
"metadata": {},
983996
"source": [
984-
"**Important Note**\n",
997+
"**Important Note about `n_jobs`**\n",
985998
"\n",
986-
"Please note that it is highly recommended to use `n_jobs=-1` (instead of `n_jobs=1`) in the previous code example to utilize all available cores on your machine and speed up the grid search. However, some Windows users reported issues when running the previous code with the `n_jobs=-1` setting related to pickling the tokenizer and tokenizer_porter functions for multiprocessing on Windows. Another workaround would be to replace those two functions, `[tokenizer, tokenizer_porter]`, with `[str.split]`. However, note that the replacement by the simple str.split would not support stemming.\n"
999+
"Please note that it is highly recommended to use `n_jobs=-1` (instead of `n_jobs=1`) in the previous code example to utilize all available cores on your machine and speed up the grid search. However, some Windows users reported issues when running the previous code with the `n_jobs=-1` setting related to pickling the tokenizer and tokenizer_porter functions for multiprocessing on Windows. Another workaround would be to replace those two functions, `[tokenizer, tokenizer_porter]`, with `[str.split]`. However, note that the replacement by the simple `str.split` would not support stemming."
1000+
]
1001+
},
1002+
{
1003+
"cell_type": "markdown",
1004+
"metadata": {},
1005+
"source": [
1006+
"**Important Note about the running time**\n",
1007+
"\n",
1008+
"Executing the following code cell **may take up to 30-60 min** depending on your machine, since based on the parameter grid we defined, there are 2*2*2*3*5 + 2*2*2*3*5 = 240 models to fit.\n",
1009+
"\n",
1010+
"If you do not wish to wait so long, you could reduce the size of the dataset by decreasing the number of training samples, for example, as follows:\n",
1011+
"\n",
1012+
" X_train = df.loc[:2500, 'review'].values\n",
1013+
" y_train = df.loc[:2500, 'sentiment'].values\n",
1014+
" \n",
1015+
"However, note that decreasing the training set size to such a small number will likely result in poorly performing models. Alternatively, you can delete parameters from the grid above to reduce the number of models to fit -- for example, by using the following:\n",
1016+
"\n",
1017+
" param_grid = [{'vect__ngram_range': [(1, 1)],\n",
1018+
" 'vect__stop_words': [stop, None],\n",
1019+
" 'vect__tokenizer': [tokenizer],\n",
1020+
" 'clf__penalty': ['l1', 'l2'],\n",
1021+
" 'clf__C': [1.0, 10.0]},\n",
1022+
" ]"
9871023
]
9881024
},
9891025
{
@@ -1255,7 +1291,7 @@
12551291
},
12561292
{
12571293
"cell_type": "code",
1258-
"execution_count": 33,
1294+
"execution_count": 27,
12591295
"metadata": {
12601296
"collapsed": true
12611297
},
@@ -1284,17 +1320,17 @@
12841320
},
12851321
{
12861322
"cell_type": "code",
1287-
"execution_count": 34,
1323+
"execution_count": 28,
12881324
"metadata": {},
12891325
"outputs": [
12901326
{
12911327
"data": {
12921328
"text/plain": [
1293-
"('\"\"\"Two Hands\"\" is a good addition to the Australian Film Catalogue.<br /><br />It is that curious mix of real life, surreal life, comedy, tragedy and love the Australians have developed on their own.<br /><br />Heath Ledger is basically a good if naive guy. Wanting to get on he falls in with a local \"\"Big\"\" Man Pando (Bryan Brown). But at the very moment he sets a first toe on the dark path to crime he meets Alex (Rose Byrne). Here is the cause of the error to change his life in ways unexpected. After getting on the wrong side of Pando accidentally, things get very bad very quickly and if not for a little otherworldly help this would have been a short sad film. Yes, Jimmy learns a few lessons in life and no one escapes uninjured in one way or another but at the end of it has a feel good feel to it. Although there is a lawless theme through the story, it is not glorified and helps to show how destructive crime can be on normal lives.<br /><br />Heath Ledger is excellent as Jimmy, innocent and savvy at the same time, Rose is hypnotic as Alex and Bryan is marvellous as usual. This is a small ensemble of characters are believable and I found myself caring about the good guys and disliking the baddies.<br /><br />This DVD is usually in the cheap aisle so I would recommend adding it too your DVD collection, it would be money well spent.<br /><br />8 out of 10\"',\n",
1329+
"('\"In 1974, the teenager Martha Moxley (Maggie Grace) moves to the high-class area of Belle Haven, Greenwich, Connecticut. On the Mischief Night, eve of Halloween, she was murdered in the backyard of her house and her murder remained unsolved. Twenty-two years later, the writer Mark Fuhrman (Christopher Meloni), who is a former LA detective that has fallen in disgrace for perjury in O.J. Simpson trial and moved to Idaho, decides to investigate the case with his partner Stephen Weeks (Andrew Mitchell) with the purpose of writing a book. The locals squirm and do not welcome them, but with the support of the retired detective Steve Carroll (Robert Forster) that was in charge of the investigation in the 70\\'s, they discover the criminal and a net of power and money to cover the murder.<br /><br />\"\"Murder in Greenwich\"\" is a good TV movie, with the true story of a murder of a fifteen years old girl that was committed by a wealthy teenager whose mother was a Kennedy. The powerful and rich family used their influence to cover the murder for more than twenty years. However, a snoopy detective and convicted perjurer in disgrace was able to disclose how the hideous crime was committed. The screenplay shows the investigation of Mark and the last days of Martha in parallel, but there is a lack of the emotion in the dramatization. My vote is seven.<br /><br />Title (Brazil): Not Available\"',\n",
12941330
" 1)"
12951331
]
12961332
},
1297-
"execution_count": 34,
1333+
"execution_count": 28,
12981334
"metadata": {},
12991335
"output_type": "execute_result"
13001336
}
@@ -1305,7 +1341,7 @@
13051341
},
13061342
{
13071343
"cell_type": "code",
1308-
"execution_count": 35,
1344+
"execution_count": 29,
13091345
"metadata": {
13101346
"collapsed": true
13111347
},
@@ -1325,11 +1361,18 @@
13251361
},
13261362
{
13271363
"cell_type": "code",
1328-
"execution_count": 36,
1329-
"metadata": {
1330-
"collapsed": true
1331-
},
1332-
"outputs": [],
1364+
"execution_count": 30,
1365+
"metadata": {},
1366+
"outputs": [
1367+
{
1368+
"name": "stderr",
1369+
"output_type": "stream",
1370+
"text": [
1371+
"/Users/sebastian/miniconda3/lib/python3.6/site-packages/sklearn/linear_model/stochastic_gradient.py:73: DeprecationWarning: n_iter parameter is deprecated in 0.19 and will be removed in 0.21. Use max_iter and tol instead.\n",
1372+
" DeprecationWarning)\n"
1373+
]
1374+
}
1375+
],
13331376
"source": [
13341377
"from sklearn.feature_extraction.text import HashingVectorizer\n",
13351378
"from sklearn.linear_model import SGDClassifier\n",
@@ -1343,18 +1386,26 @@
13431386
"doc_stream = stream_docs(path='movie_data.csv')"
13441387
]
13451388
},
1389+
{
1390+
"cell_type": "markdown",
1391+
"metadata": {},
1392+
"source": [
1393+
"**Note**\n",
1394+
"\n",
1395+
"- You can replace `Perceptron(n_iter, ...)` by `Perceptron(max_iter, ...)` in scikit-learn >= 0.19. The `n_iter` parameter is used here deriberately, because some people still use scikit-learn 0.18.\n"
1396+
]
1397+
},
13461398
{
13471399
"cell_type": "code",
1348-
"execution_count": 37,
1400+
"execution_count": 31,
13491401
"metadata": {},
13501402
"outputs": [
13511403
{
13521404
"name": "stderr",
13531405
"output_type": "stream",
13541406
"text": [
1355-
"0% 100%\n",
1356-
"[##############################] | ETA: 00:00:00\n",
1357-
"Total time elapsed: 00:00:39\n"
1407+
"0% [##############################] 100% | ETA: 00:00:00\n",
1408+
"Total time elapsed: 00:00:31\n"
13581409
]
13591410
}
13601411
],
@@ -1374,14 +1425,14 @@
13741425
},
13751426
{
13761427
"cell_type": "code",
1377-
"execution_count": 38,
1428+
"execution_count": 32,
13781429
"metadata": {},
13791430
"outputs": [
13801431
{
13811432
"name": "stdout",
13821433
"output_type": "stream",
13831434
"text": [
1384-
"Accuracy: 0.878\n"
1435+
"Accuracy: 0.867\n"
13851436
]
13861437
}
13871438
],
@@ -1393,7 +1444,7 @@
13931444
},
13941445
{
13951446
"cell_type": "code",
1396-
"execution_count": 39,
1447+
"execution_count": 33,
13971448
"metadata": {
13981449
"collapsed": true
13991450
},
Binary file not shown.

0 commit comments

Comments
 (0)