Path: blob/master/april_18/lessons/lesson-19-flex/19-Neural Networks-Solutions.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 [3]:
Out[3]:
(1000, 1) (1000, 1)
In [4]:
In [5]:
Out[5]:
Training...
Done
In [6]:
Out[6]:
MSE 0.0847152073854
Sine Regression
In [7]:
Out[7]:
(500, 1) (500, 1)
In [8]:
Train the Model
In [9]:
Out[9]:
Training..
0.0141807238509
Complete
In [10]:
Out[10]:
MSE 0.0756651529904
In [11]:
Out[11]:
<matplotlib.text.Text at 0x7fa6843cb898>
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 [16]:
Out[16]:
(150, 4) (150, 3)
In [17]:
In [18]:
Out[18]:
Training...
0.102203034196
Training complete
In [19]:
Out[19]:
ACCURACY: 0.666666666667
CONFUSION MATRIX:
[[50 0 0]
[ 0 50 0]
[ 0 50 0]]
In [20]:
Out[20]:
<matplotlib.text.Text at 0x7fa681fbc0b8>
Abalone data set
In [21]:
Out[21]:
In [22]:
Out[22]:
In [23]:
In [24]:
Out[24]:
(4177, 8) (4177, 3)
In [25]:
In [26]:
Out[26]:
Training...
0.173390359594
Training complete
In [27]:
Out[27]:
ACCURACY: 0.550873832894
CONFUSION MATRIX:
[[1260 3 265]
[1157 1 149]
[ 302 0 1040]]
<matplotlib.text.Text at 0x7fa67fea9940>
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 [ ]: