In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from bokeh.charts import Scatter, show
from bokeh.plotting import figure
from bokeh.io import output_notebook
output_notebook()
df = pd.read_csv('../MA490-MachineLearning-FinalProject//sineData5.csv')


BokehJS successfully loaded.

In [2]:
df['Actual'] = np.zeros(100)
for i in range(100): 
    df['Actual'].values[i] = np.sin(df['Input'].values[i])
    
df.head()


Out[2]:
Input Prediction Actual
0 -15.7 -64400 -0.007963
1 -15.4 -46600 -0.303118
2 -15.1 -33400 -0.571197
3 -14.8 -23700 -0.788252
4 -14.4 -16600 -0.965658

In [11]:
fig = Scatter(df[20:80], x='Input',y='Prediction',color='blue')
f = figure()
f.line(df.Input.values[18:82], df.Prediction.values[18:82], color='blue')
x = np.linspace(-3*np.pi-np.pi/2, 3*np.pi+np.pi/2, 100)
y = np.sin(x)
f.line(x,y,color='red')
x = [-3*np.pi,-3*np.pi]
y = [-3,3]
f.line(x,y,color='black')
x = [3*np.pi,3*np.pi]
y = [-3,3]
f.line(x,y,color='black')
show(f)


Out[11]:
<bokeh.io._CommsHandle at 0xa0ed6d8>
sine(x): Calculates the sine of x.

Using skflow and its library I trained a TensorFlowDNNRegressor with 9 hidden units.
Process:

  • Originally trained using random data by picking random numbers between 0 and 1000 and converting to radians

    • Trained over 10,000 iterations.
    • Used 2 hidden units.
    • Had very high error.
  • Next used 0 to 720 degrees and fed all the values to the net.

    • Trained over 10,000 iterations.
    • Used 2 hidden units.
    • Still had very high error, didn't seem to learn very well.
  • Generated 10000 numbers between -π to π and fed the neural network the sine taylor expansion (9 of the terms) for each value.

    • Trained over 10,000 iterations.
    • Used 9 hidden units.
    • Was much more accurate than the previous attempts, can predict in the range between -pi and pi almost spot on.
    • As you increase the range the prediction becomes less accurate and heads off to infinite and can't seem to generalize the sine curve.
  • Generated 10000 numbers between -3π to 3π
    • Trained over 100,000 iterations
    • Used 9 hidden units
    • Still accurate between -3π and 3π yet outside of that range still expands to infinity

In [ ]: