-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNN.py
More file actions
33 lines (19 loc) · 841 Bytes
/
Copy pathTestNN.py
File metadata and controls
33 lines (19 loc) · 841 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
32
import numpy as np
from scipy.io import loadmat
from scipy.optimize import check_grad
import SimpleNN
import Train
mat = loadmat('..\\ex4weights.mat')
s = SimpleNN.SimpleNN([400, 25, 10])
s.theta = [np.transpose(mat["Theta1"]), np.transpose(mat["Theta2"])]
data = loadmat("..\\ex4data1.mat")
x = data["X"][:500,:]
y = data["y"][:500]
#check_grad(func = lambda p: s.computeCost(s.combineTheta(p), x, y, 0.5),
# grad = lambda p: s.computeGrad(s.combineTheta(p), x, y, 0.5),
# x0 = s.combineTheta(s.theta))
#(cost, grad) = s.computeCostGrad(s.theta, x, y, 1)
s = Train.trainSciPy(s, x, y, 0.05)
predictions = [s.predictClass(w) for w in x]
err_rate = np.mean([1 if pred != check else 0 for (pred, check) in zip(y, predictions)])
print("Error rate with pre-computed paramaters: {0}".format(err_rate))