In [2]:
cd ../backprop
In [14]:
%pylab inline
from nn_scipy_opti import NN_1HL
import numpy as np
from sklearn import cross_validation
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
from pprint import pprint
import scipy.io
import time
In [4]:
def test_simple_backprop(data, labels, hidden_nodes, iterations, maxiter=200, plot=False):
times = []
accuracy = []
for i in range(iterations):
X_train, X_test, y_train, y_test = cross_validation.train_test_split(data, labels, test_size=0.2)
nn = NN_1HL(maxiter=maxiter, hidden_layer_size=hidden_nodes)
time_now = time.time()
nn.fit(X_train, y_train)
times.append( time.time() - time_now )
accuracy.append(accuracy_score(y_test, nn.predict(X_test)))
return np.mean(accuracy),np.mean(times),accuracy,times
In [21]:
data_file = scipy.io.loadmat('../data/mat/ball_with_speed.mat')
data = np.array(data_file['X'])
labels = np.array(data_file['Y'], 'uint8').T
labels = labels[0,:].flatten()
print
In [17]:
a,b,c,d = test_simple_backprop(data, labels, 20, 3, 400)
print a
print b
print c
print d
In [24]:
data_1 = data/255
a,b,c,d = test_simple_backprop(data_1, labels, 20, 3, 400)
print a
print b
print c
print d
In [25]:
data_1 = data/255
a,b,c,d = test_simple_backprop(data_1, labels, 23, 4, 600)
print a
print b
print c
print d