Commit 73e716a6 authored by Jon Krohn's avatar Jon Krohn
Browse files

MNIST loaded locally

parent 93f89f46
Loading
Loading
Loading
Loading

data/mnist_X_test.pkl

0 → 100644
+7.48 MiB

File added.

No diff preview for this file type.

data/mnist_X_train.pkl

0 → 100644
+44.9 MiB

File added.

No diff preview for this file type.

data/mnist_y_test.pkl

0 → 100644
+9.92 KiB

File added.

No diff preview for this file type.

data/mnist_y_train.pkl

0 → 100644
+58.7 KiB

File added.

No diff preview for this file type.

+6 −1
Changes for notebooks/shallow_net_in_keras_LT.ipynb: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

# Shallow Neural Network in Keras

%% Cell type:markdown id: tags:

Build a shallow neural network to classify MNIST digits

%% Cell type:markdown id: tags:

#### Set seed for reproducibility

%% Cell type:code id: tags:

``` python
import numpy as np
np.random.seed(42)
```

%% Cell type:markdown id: tags:

#### Load dependencies

%% Cell type:code id: tags:

``` python
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
```

%% Cell type:markdown id: tags:

#### Load data

%% Cell type:code id: tags:

``` python
(X_train, y_train), (X_test, y_test) = mnist.load_data()
#(X_train, y_train), (X_test, y_test) = mnist.load_data()
import pickle
X_train = pickle.load(open('../data/mnist_X_train.pkl', 'rb'))
y_train = pickle.load(open('../data/mnist_y_train.pkl', 'rb'))
X_test = pickle.load(open('../data/mnist_X_test.pkl', 'rb'))
y_test = pickle.load(open('../data/mnist_y_test.pkl', 'rb'))
```

%% Cell type:code id: tags:

``` python
X_train.shape
```

%% Cell type:code id: tags:

``` python
y_train.shape
```

%% Cell type:code id: tags:

``` python
y_train[0:99]
```

%% Cell type:code id: tags:

``` python
X_test.shape
```

%% Cell type:code id: tags:

``` python
X_test[0]
```

%% Cell type:code id: tags:

``` python
y_test.shape
```

%% Cell type:code id: tags:

``` python
y_test[0]
```

%% Cell type:markdown id: tags:

#### Preprocess data

%% Cell type:code id: tags:

``` python
X_train = X_train.reshape(60000, 784).astype('float32')
X_test = X_test.reshape(10000, 784).astype('float32')
```

%% Cell type:code id: tags:

``` python
X_train /= 255
X_test /= 255
```

%% Cell type:code id: tags:

``` python
X_test[0]
```

%% Cell type:code id: tags:

``` python
n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes)
```

%% Cell type:code id: tags:

``` python
y_test[0]
```

%% Cell type:markdown id: tags:

#### Design neural network architecture

%% Cell type:code id: tags:

``` python
# add architecture here
```

%% Cell type:code id: tags:

``` python
model.summary()
```

%% Cell type:code id: tags:

``` python
(64*784)
```

%% Cell type:code id: tags:

``` python
(64*784)+64
```

%% Cell type:code id: tags:

``` python
(10*64)+10
```

%% Cell type:markdown id: tags:

#### Configure model

%% Cell type:code id: tags:

``` python
# compile model here
```

%% Cell type:markdown id: tags:

#### Train!

%% Cell type:code id: tags:

``` python
# train model here
```

%% Cell type:code id: tags:

``` python
model.evaluate(X_test, y_test)
```

%% Cell type:code id: tags:

``` python
```
Loading