Neural Network

Open In Colab Binder

Notebook producing the figures in Linear Regression to Neural Networks. Chapter on Neural Networks. We are going to fit a Neural Network model to try and classify some Penguin species data. We are going to produce this plot:

neural network fit

Let's go!

For all source files, see Github repository.

Load Penguin dataset.

Make column for only indicating Chinstrap yes/no.

Training/testing cross validation split. Reserve 1/4th of data for testing.

Let's try to classify Chinstraps using a Neural Network. We'll use sklearn for this. Try a fit:

Test classifier score() function.

Next, we create a function to predict our classifier over a grid points, to be used for plotting our decision regions later.

Wrap our clf object in a predictor variable.

Run some couple thousand iterations using our Neural Network. It has a rather 'arbitrary' architecture of 3 layers of 5 nodes each - should be enough to capture the complexity of this dataset.

Collect results in a DataFrame and plot loss and accuracy.

Plot decision region of last fit.

We are going to create a range of images. Create a temporary folder for them.

Compute and save separate GIF images.

Convert separate images into a GIF.

Clean the temporary folder 💎

Author

Code written by Jeroen Overschie. MIT licensed.