-
Notifications
You must be signed in to change notification settings - Fork 0
/
testNeuralNetDigits.py
55 lines (40 loc) · 1.15 KB
/
testNeuralNetDigits.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
======================================================
Test of Neural Nets on Digits data
======================================================
Author: Michael O'Meara, 2014
"""
print(__doc__)
import numpy as np
from sklearn import datasets
from sklearn.metrics import accuracy_score
from nn import NeuralNet
# load the data set
filename = 'data/digitsX.dat'
file = open(filename, 'r')
digitsX = np.loadtxt(file, delimiter=',')
filename = 'data/digitsY.dat'
file = open(filename, 'r')
digitsY = np.loadtxt(file, delimiter=',')
# dataset = datasets.load_digits()
X = digitsX[:]
y = digitsY[:]
n,d = X.shape
nTrain = 0.2*n #training on 50% of the data
# shuffle the data
# idx = np.arange(n)
# np.random.seed(13)
# np.random.shuffle(idx)
# X = X[idx]
# y = y[idx]
# split the data
Xtrain = X[:nTrain,:]
ytrain = y[:nTrain]
# Xtest = X[nTrain:,:]
# ytest = y[nTrain:]
model = NeuralNet(np.array([25]), .80, 0.12, 600) # 100 @ 2.5 = 0.885, 400 @ 1.6 = 0.88, 1000 @ 1 = 0.8542,
model.fit(X,y)
ypred = model.predict(Xtrain)
accuracy = accuracy_score(ytrain, ypred)
print "NeuralNet Accuracy = "+str(accuracy)
# model.visualizeHiddenNodes('hiddenLayers.png')