Skip to content

Commit d4f8a10

Browse files
committed
Ch 8 Code pt 1
1 parent 7031b3d commit d4f8a10

File tree

6 files changed

+722
-29
lines changed

6 files changed

+722
-29
lines changed

7_marbles_test.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

8.1 Unit Testing Data.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import marbles.core\n",
10+
"from marbles.mixins import mixins\n",
11+
"\n",
12+
"import pandas as pd\n",
13+
"import numpy as np\n",
14+
"from datetime import datetime, timedelta\n",
15+
"\n",
16+
"class TimeSeriesTestCase(marbles.core.TestCase,mixins.MonotonicMixins):\n",
17+
" def setUp(self):\n",
18+
" self.df = pd.DataFrame({'dates':[datetime(2018,1,1),\n",
19+
" datetime(2018,2,1),\n",
20+
" datetime(2018,2,1)],\n",
21+
" 'ireland_unemployment':[6.2,6.1,6.0]})\n",
22+
" \n",
23+
" def tearDown(self):\n",
24+
" self.df = None\n",
25+
" \n",
26+
" def test_date_order(self):\n",
27+
" \n",
28+
" self.assertMonotonicIncreasing(sequence=self.df.dates,\n",
29+
" note = 'Dates need to increase monotonically')\n",
30+
" "
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 2,
36+
"metadata": {},
37+
"outputs": [
38+
{
39+
"name": "stderr",
40+
"output_type": "stream",
41+
"text": [
42+
"F\n",
43+
"======================================================================\n",
44+
"FAIL: test_date_order (__main__.TimeSeriesTestCase)\n",
45+
"----------------------------------------------------------------------\n",
46+
"marbles.core.marbles.ContextualAssertionError: Elements in 0 2018-01-01\n",
47+
"1 2018-02-01\n",
48+
"2 2018-02-01\n",
49+
"Name: dates, dtype: datetime64[ns] are not strictly monotonically increasing\n",
50+
"\n",
51+
"Source (<ipython-input-1-ebdbd8f0d69f>):\n",
52+
" 19 \n",
53+
" > 20 self.assertMonotonicIncreasing(sequence=self.df.dates,\n",
54+
" 21 note = 'Dates need to increase monotonically')\n",
55+
" 22 \n",
56+
"Locals:\n",
57+
"\n",
58+
"Note:\n",
59+
"\tDates need to increase monotonically\n",
60+
"\n",
61+
"\n",
62+
"----------------------------------------------------------------------\n",
63+
"Ran 1 test in 0.007s\n",
64+
"\n",
65+
"FAILED (failures=1)\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"if __name__ == '__main__':\n",
71+
" marbles.core.main(argv=['first-arg-is-ignored'], exit=False)"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": null,
77+
"metadata": {},
78+
"outputs": [],
79+
"source": []
80+
}
81+
],
82+
"metadata": {
83+
"anaconda-cloud": {},
84+
"kernelspec": {
85+
"display_name": "Python [default]",
86+
"language": "python",
87+
"name": "python3"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 3
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython3",
99+
"version": "3.5.4"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 2
104+
}

8.3 Tensorboard debugging.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
# coding: utf-8
3+
4+
# In[1]:
5+
6+
7+
from keras.datasets import mnist
8+
9+
(x_train, y_train), (x_test, y_test) = mnist.load_data()
10+
11+
12+
# In[2]:
13+
14+
15+
from keras.models import Sequential
16+
from keras.layers import Dense
17+
18+
x_train.shape = (60000, 28 * 28)
19+
20+
21+
x_test.shape = (10000, 28 * 28)
22+
23+
24+
x_train = x_train / 255
25+
x_test = x_test / 255
26+
27+
model = Sequential()
28+
model.add(Dense(512,activation='relu',input_dim= 28*28))
29+
model.add(Dense(512,activation='relu'))
30+
model.add(Dense(512,activation='relu'))
31+
model.add(Dense(10,activation='softmax'))
32+
33+
model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['acc'])
34+
35+
from keras.callbacks import TensorBoard
36+
37+
import tensorflow as tf
38+
from tensorflow.python import debug as tf_debug
39+
import keras
40+
41+
keras.backend.set_session(
42+
tf_debug.TensorBoardDebugWrapperSession(tf.Session(), "localhost:2018"))
43+
44+
45+
46+
47+
hist = model.fit(x_train*255,y_train,batch_size=128,epochs=5,validation_data=(x_test*255,y_test))
48+

0 commit comments

Comments
 (0)