Path: blob/master/april_18/lessons/lesson-19-flex/19-Neural Networks.ipynb
1904 views
Kernel: Python [Root]
Neural Networks with Keras
In [2]:
Neural Network Regression
Polynomial Regression
Let's train a neural network on a few different shapes. First we start with a polynomial (a cubic).
In [5]:
Out[5]:
(1000, 1) (1000, 1)
In [3]:
In [6]:
Out[6]:
Training...
0.0854882331689
Done
In [7]:
Out[7]:
MSE 0.0855282084513
Sine Regression
In [9]:
Out[9]:
(500, 1) (500, 1)
In [10]:
Train the Model
In [11]:
Out[11]:
Training..
0.0126229299853
Complete
In [12]:
Out[12]:
MSE 0.0693315698424
In [13]:
Out[13]:
<matplotlib.text.Text at 0x7f1656633e90>
Train longer
If we train for more epochs, we can get a better regression.
In [12]:
Out[12]:
(1000, 1) (1000, 1)
Training..
0.00057795047718
Complete
MSE 0.00133023607819
We can take a closer look at the error per training epoch.
In [13]:
Out[13]:
<matplotlib.text.Text at 0x7fa684022358>
In [14]:
Out[14]:
(1000, 1) (1000, 1)
In [15]:
Out[15]:
Training..
0.0916458962692
Complete
MSE 1.28391965568
Classification
We'll start with the Iris dataset (of course).
In [14]:
Out[14]:
(150, 4) (150, 3)
In [16]:
In [17]:
Out[17]:
Training...
0.0117153188358
Training complete
In [18]:
Out[18]:
ACCURACY: 0.993333333333
CONFUSION MATRIX:
[[50 0 0]
[ 0 49 1]
[ 0 0 50]]
In [19]:
Out[19]:
<matplotlib.text.Text at 0x7f165443ff10>
Abalone data set
In [20]:
Out[20]:
In [22]:
Out[22]:
In [21]:
In [22]:
Out[22]:
(4177, 8) (4177, 3)
In [23]:
In [24]:
Out[24]:
Training...
0.173071733933
Training complete
In [25]:
Out[25]:
ACCURACY: 0.545846301173
CONFUSION MATRIX:
[[1155 72 301]
[1031 80 196]
[ 275 22 1045]]
<matplotlib.text.Text at 0x7f16540ba210>
Exercise
Classify the following data (source). You'll need to translate the classes into integers and make dummies. Design a neural network to classify the data and evaluate the results.
In [28]:
Out[28]:
In [29]:
In [30]:
Out[30]:
(19020, 10) (19020, 2)
In [31]:
In [32]:
Out[32]:
Training...
0.108597032569
Training complete
In [33]:
Out[33]:
ACCURACY: 0.799158780231
CONFUSION MATRIX:
[[11670 662]
[ 3158 3530]]
<matplotlib.text.Text at 0x7fa68421df98>
In [ ]:
In [ ]: