-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (23 loc) · 705 Bytes
/
Copy pathutils.py
File metadata and controls
31 lines (23 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
from network import Network
def train_set():
return np.loadtxt('data/mnist_train.csv', delimiter=',')
def test_set():
return np.loadtxt('data/mnist_test.csv', delimiter=',')
def accuracy(network, inputs, targets):
outputs = np.array([network.forward(inp) for inp in inputs])
predictions = np.argmax(outputs, axis=1)
accur = 100 * np.mean(predictions == targets)
return accur
def num_to_probability(num):
x = np.zeros(10)
x[int(num)] = 0.99
return x
# save.py
import pickle
def save_model(model, filename="model.pkl"):
with open(filename, "wb") as f:
pickle.dump(model, f)
def load_model(filename="model.pkl"):
with open(filename, "rb") as f:
return pickle.load(f)