In [2]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from IPython.html.widgets import interact
import sknn.mlp as neurnet
from sklearn.datasets import load_digits
digits = load_digits()
trainingdata = digits.data[0:1200]
traininganswers = digits.target[0:1200]
lc = 0.02
#convert the integer answers into a 10-dimension array
traininganswervectors = np.zeros((1200,10))
for n in range(1200):
traininganswervectors[n][digits.target[n]] = 1
testdata = digits.data[1200:1700]
testanswers = digits.target[1200:1700]
testanswervectors = np.zeros((500,10))
for n in range(500):
testanswervectors[n][digits.target[n + 1200]] = 1
trainingtuples = np.array(zip(trainingdata, traininganswervectors))
testtuples = np.array(zip(testdata, testanswervectors))
In [3]:
def accuracy(inputs, results, answers):
correct = 0
binresults = results
for n in range(0, len(results)):
#converts the output into a binary y/n for each digit
for n2 in range(len(results[n])):
if results[n][n2] == max(results[n]):
binresults[n][n2] = 1
else:
binresults[n][n2] = 0
if np.array_equal(answers[n], binresults[n]):
correct += 1
return correct / len(results)
In [30]:
time = [9.9, 9.54, 9.24, 9.73, 11.7, 12.9, 12.4]
acc = [0.924, 0.9, 0.898, 0.846, 0.09, 0.1, 0.1]
plt.scatter(time, acc)
plt.xlabel("Time")
plt.ylabel("Accuracy")
Out[30]:
In [38]:
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(time[0:4], acc[0:4])
ax.annotate("1x80", xy=(9.9, 0.928))
ax.annotate("2x40", xy=(9.54, 0.905))
ax.annotate("4x20", xy=(9.24, 0.902))
ax.annotate("8x10", xy=(9.73, 0.850))
Out[38]:
In [18]:
_1x80time = [.478, .364, .435, 1.01, 1.77, 3.47, 5.27, 6.98, 8.77, 10.5, 34.9]
_1x80acc = [.864, .858, .876, .896, .906, .914, .916, .922, .924, .926, .924]
In [19]:
_4x20time = [.193, .317, .541, .833, 1.68, 3.33, 5.02, 6.76, 8.67, 10.1, 35.6]
_4x20acc = [.43, .526, .776, .864, .88, .894, .9, .898, .898, .898, .896]
In [33]:
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(_1x80time, _1x80acc)
plt.scatter(_4x20time, _4x20acc, color="r")
ax.set_xscale("log")
plt.xlabel("Time (log)")
plt.ylabel("Accuracy")
plt.ylim(0, 1)
Out[33]:
In [ ]: