In [103]:
from __future__ import print_function
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
matplotlib.style.use('ggplot')
%matplotlib inline
After several tests we found in almost all cases that training a function on every possibility is much more effective than randomly generating data.
In [104]:
data_inorder = pd.read_csv('Data\\adder_inorder_data.csv')
data_inorder = data_inorder[['Steps', 'MSE']]
data_inorder = data_inorder.sort_values(['Steps'])
data_inorder.head(9)
Out[104]:
In [105]:
data_rnd_0 = pd.read_csv('Data\\adder_random_0_data.csv')
data_rnd_0 = data_rnd_0[['Steps', 'MSE']]
data_rnd_0 = data_rnd_0.sort_values(['Steps'])
data_rnd_1 = pd.read_csv('Data\\adder_random_1_data.csv')
data_rnd_1 = data_rnd_1[['Steps', 'MSE']]
data_rnd_1 = data_rnd_1.sort_values(['Steps'])
data_rnd_2 = pd.read_csv('Data\\adder_random_2_data.csv')
data_rnd_2 = data_rnd_2[['Steps', 'MSE']]
data_rnd_2 = data_rnd_2.sort_values(['Steps'])
data_rnd_3 = pd.read_csv('Data\\adder_random_3_data.csv')
data_rnd_3 = data_rnd_3[['Steps', 'MSE']]
data_rnd_3 = data_rnd_3.sort_values(['Steps'])
data_rnd_4 = pd.read_csv('Data\\adder_random_4_data.csv')
data_rnd_4 = data_rnd_4[['Steps', 'MSE']]
data_rnd_4 = data_rnd_4.sort_values(['Steps'])
In [106]:
plt.plot(data_inorder['Steps'].ix[:20], data_inorder['MSE'].ix[:20], 'bo',
data_rnd_0['Steps'].ix[:20], data_rnd_0['MSE'].ix[:20],
data_rnd_1['Steps'].ix[:20], data_rnd_1['MSE'].ix[:20],
data_rnd_2['Steps'].ix[:20], data_rnd_2['MSE'].ix[:20],
data_rnd_3['Steps'].ix[:20], data_rnd_3['MSE'].ix[:20],
data_rnd_4['Steps'].ix[:20], data_rnd_4['MSE'].ix[:20])
plt.show()
In [107]:
plt.plot(data_inorder['Steps'].ix[30:], data_inorder['MSE'].ix[30:], 'bo',
data_rnd_0['Steps'].ix[30:], data_rnd_0['MSE'].ix[30:],
data_rnd_1['Steps'].ix[30:], data_rnd_1['MSE'].ix[30:],
data_rnd_2['Steps'].ix[30:], data_rnd_2['MSE'].ix[30:],
data_rnd_3['Steps'].ix[30:], data_rnd_3['MSE'].ix[30:],
data_rnd_4['Steps'].ix[30:], data_rnd_4['MSE'].ix[30:])
plt.show()
In [108]:
plt.plot(data_rnd_1['Steps'].ix[30:], data_rnd_1['MSE'].ix[30:],
data_rnd_2['Steps'].ix[30:], data_rnd_2['MSE'].ix[30:],
data_rnd_4['Steps'].ix[30:], data_rnd_4['MSE'].ix[30:])
plt.show()
Process:
Results:
Data | MSE |
100 data: 1-100 | .065861 |
1000 datum: random(100) | .028475 |
1000 datum: 1-100 10 times | .007759 |
10000 datum: 1-100 100 times | 409.116 |
The results seemed to show that iterating through every possibility multiple times and then training on that is the best method of data gathering. As with many things in this, you have to find the fine line of having the right amount of data without having too much.
I was interested in how far a neural net could extrapolate to numbers that it had never seen before. Although this should have been an easy problem because it is linear, it wasn't because SkFlow doesn't allow you to choose the activation function for your regressor. Most all of the single and double layer neural nets I trained failed around 200-300, however there was one that stood out and was able to correctly predict 1-1145 with just training on 1-100
In [109]:
data_inorder = pd.read_csv('Data\\adder_inorder_data.csv')
data_inorder = data_inorder[['Steps', 'MSE']]
data_inorder = data_inorder.sort_values(['Steps'])
In [110]:
arr = np.zeros(5)
arr[0] = 5
In [111]:
arr = ['100', '200', '300', '400', '500', '600', '700',
'1000','1100','1200','1300', '1400','1500', '1600','1700','1800', '1900',
'2000', '2100', '2300', '2400', '2500']
df_arr = []
for i in range(len(arr)):
temp = pd.read_csv('Data\\determinant_' + arr[i] +'_layer_by_100.csv', header=None)
temp = temp.T
temp.columns=['Second', 'MSE']
temp['First'] = arr[i]
temp = temp.sort_values(['First', 'Second'])
df_arr.append(temp)
len(df_arr)
Out[111]:
In [ ]:
temp = pd.read_csv('Data\\determinant_layer_by_100.csv', header=None)
temp = temp.T
temp.columns=['Second', 'MSE']
In [131]:
frames = [df_arr[0], df_arr[1], df_arr[2], df_arr[3], df_arr[4], df_arr[5],
df_arr[6], df_arr[7], df_arr[8], df_arr[9], df_arr[10], df_arr[11],
df_arr[12], df_arr[13], df_arr[14], df_arr[15], df_arr[16], df_arr[17],
df_arr[18], df_arr[19], df_arr[20], df_arr[21]]
result = pd.concat(frames)
result = result.reset_index(drop=True)
result.sort_values(['MSE'])
Out[131]:
In [113]:
res1 = result.as_matrix(columns=['First'])
res2 = result.as_matrix(columns=['Second'])
res3 = result.as_matrix(columns=['MSE'])
In [114]:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(res1[:,0], res2[:,0], res3[:,0], cmap=cm.jet, linewidth=0.2)
plt.show()
In [117]:
min = 30
for i in range(len(arr)):
plt.plot(df_arr[i]['Second'], df_arr[i]['MSE'])
plt.show()
In [130]:
num = 5
df_arr[5].as_matrix(columns=['MSE']))
df_arr[5].head(21)
Out[130]:
In [118]:
for i in range(len(arr)):
plt.plot(df_arr[i]['Second'], df_arr[i]['MSE'])
plt.ylim(.3, .5)
plt.show()
In [120]:
plt.plot(df_arr[0]['Second'], df_arr[0]['MSE'])
Out[120]:
In [ ]:
In [ ]:
In [71]:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
n_angles = 36
n_radii = 8
# An array of radii
# Does not include radius r=0, this is to eliminate duplicate points
radii = np.linspace(0.125, 1.0, n_radii)
# An array of angles
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
# Repeat all angles for each radius
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
# Convert polar (radii, angles) coords to cartesian (x, y) coords
# (0, 0) is added here. There are no duplicate points in the (x, y) plane
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())
# Pringle surface
z = np.sin(-x*y)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
plt.show()
In [75]:
z
Out[75]:
In [ ]:
arr np.array()