Part Three: Keras for Deep Learning

Here we start building the models themselves. You will learn exactly how to construct, compile, train, evaluate and make predictions with your neural network. You will see issues that classification tasks have with under-represented classes and how we can fix this with weight adjustments.

This week please read either of the following (preferably the first):
8 - Keras and our First Project
9 - How to Build a Neural Network in Keras
10 - Dealing with Poorly Distributed Class Data
11 - Summary
Programming Exercises
1) US Taxpayer Classification

Welcome to the first project of this course. You will apply all that you have learned to build a basic classification neural network to predict which political party someone will vote for based on their tax returns. You will take many things for granted, such as the NN architecture since this is the aim for the next part of the course. You will observe that you get a poor out-of-sample accuracy and this should motivate you to learn how you can improve such a model.

The data is taken from:

You need to download the files from the Google Drive below and make sure that you place them all in the same folder.

After downloading, open the WORKBOOK file and work through it. The workbook is seperated into parts that you have to code and other parts that you just have to follow along. Only enter your code where we ask you to, else it might break the workbook. Your work will be autograded, but if you get stuck, refer to the SOLUTIONS workbook for suggested solutions. You do not need to touch the other files.

2) X-Ray Pneumonia Detection

In this workbook, we expose you to a different type of data, namely images. The main purpose of this is to get you building another NN in Keras and also to implement a class_weight function to deal with poorly distributed class data.

You will get a better result in this workbook compared to the last one, and will end up with a model that predicts whether a patient has pneumonia or not with good accuracy.

You need to download the files from the Google Drive below and make sure that you place them all in the same folder.


  1. Download the files below - note: this is over 1GB so may take some time. If you do not have time/space then do not download the chest_xray folder and WORKBOOK 1.

  2. WORKBOOK 1 walks through the process of importing, labelling and sorting the data. There is nothing for you to do here, but read through carefully.

  3. WORBOOK 2 contains parts that you need to fill in. Like the last assignment, only fill in the parts that we ask you to. Only look at the solutions if you get stuck.

The data comes from:

End of Part Three

Well done for making it this far - You can now build a neural network! However, there is still a lot to cover in terms of how to choose all the hyperparameters for the model, such as number of hidden layers, neurons per layer, which optimiser to choose, and much much more.

This will be the focus of Part Four, which makes up a large chunk of this course. See you there!

  • Black YouTube Icon
  • Black LinkedIn Icon