[NEW] TensorFlow (Beginner): Predicting House Prices with Regression

In this project, we are going to create and train a neural network to perform a regression task. In a regression task, we train the network to predict a continuous value given a set of input features. By the end of this project, you’d have created and trained a neural network to be able to predict prices of houses given a bunch of features.

Join for Free
[NEW] TensorFlow (Beginner): Predicting House Prices with Regression

Duration (mins)

Learners

4.7 / 5

Rating

Task List


We will cover the following tasks in 48 minutes:


Introduction

In this project, we are looking to solve a regression problem with the help of a neural network model and some data. In a regression task, we train the network to predict a continuous value given a set of input features. This is different from classification - in classification problems, we train a model to predict discreet values or classes. To be able to complete this project successfully, you should have a basic understanding of programming with python. It would also help if you have used Jupyter Notebooks before.

You should have a basic understanding of how neural networks work as well. It’s okay if you don’t understand the math behind neural networks because we are going to use a high level API, but I will assume that have some conceptual understanding of neural networks.


Importing the Data

First of all, we will import the dataset. We will use the popular Pandas library to import and process the data. The head() function gives us the first 5 rows by default. So, we can see the typical values for our features as given in the dataset. There are 5000 examples in the dataset and it may not be possible for us to go through all of them manually. So, we want to ensure that there aren’t any missing values in the dataset before we start using it. Pandas makes it really simple. We can use the isna() function to find out any missing or not available values in the dataset.


Data Normalization

We can make it easier for optimization algorithms to converge towards minimas faster by normalizing the data before training a model. You may remember that a neural network model is trained with the help of an optimization algorithm that tries to minimize the difference between ground truth or actual labels and model’s predictions. Normalization of data makes it easier for such an optimization algorithm to take gradient steps in the right direction more consistently. Normalization is simply changing the distribution of different features so that the values for different features are in similar ranges.

We will ignore the first column because it’s not a feature and is just a serial number. Then we will normalize the data by using mean and standard deviation of each column. This operation is column-wise by default.


Training and Test Sets

In this task, we will split our Data Frame into the features and the labels and then we will split that data into two sets: one for training and another one for testing. In pandas, we have an option to split data by columns by using iloc for specifying location. Let’s look at our Data Frame’s head that we printed out in the last task after normalization. Notice only the first 6 columns of the Data Frame are the features, so let’s store them separately as X. We will use a helper function called train_test_split from SciKit Learn to do this split. The reason we are using this helper function is because not only this will very conveniently split our data in the two sets that we need, it will also randomly shuffle the input data before splitting it. This random shuffle is a pretty good idea: if the observations were recorded or arranged in any kind of order for any column, for example, then that pattern may influence our neural network into finding correlations that depend on how the data was observed or stored rather than finding actual meaningful correlations which generalize well.


Create the Model

Let’s write a function that returns an untrained model of a certain architecture. We are using a simple neural network architecture with just 3 hidden layers. We are going to use the relu activation function on all the layers except for the output layer. Since this is a regression problem, we just need the linear output without any activation here.

Mean squared error is pretty common for regression problems. Remember, this is the loss function that the optimization algorithm tries to minimize. We are using a variant of stochastic gradient descent algorithm which is called adam. At a beginner level, it’s okay if you don’t understand the exact math behind this as long as you understand what an optimization algorithm is.


Model Training

Usually, we don’t know in advance how long we may need to train a model for. Fortunately, we can use an EarlyStopping callback from Keras to stop the model training if the validation loss stops decreasing for a few epochs. The validation loss is calculated on the test set and not on the training set so it’s a better metric to use to make a decision on stopping the training.

By using early stopping callback, we can be generous with the epoch value here and set it to a very high number and the model will simply stop training when it doesn’t see any improvement in validation loss in 5 subsequent epochs.


Predictions

Previously, we had stored predictions from an untrained model in a variable called preds_on_untrained. Now that we have the trained model, let’s store predictions from a trained model on the same test set in another variable. Now, let’s use the compare_predictions helper function to compare predictions from the model when it was untrained and when it was trained.

The trained model predictions are in green and the untrained on in red. This makes sense. The untrained model predictions are quite random and the trained model predictions are more close to this blue line which is the ground truth or the actual values of prices for this set. So, we can see that after the training, the model does a significantly better job at predictions.

Watch Preview

Preview the instructions that you will follow along in a hands-on session in your browser.

Reviews


There was some lag issues but in the end, everything went fine.

Amirul Arif
Amirul Arif

Be careful. I have a Mac and and I don't Type this [] (hook parenthese)

vignaux
vignaux

my VGA got very hot = protection reset. (old desk, Quadro 2k) I'm thinking in others alternatives. The interaction is very good. Congrats. I liked it. Thank you!

Elven Jr
Elven Jr

Some matters are better taught when the video is not showing a notebook. With regards to teh cloud desktop, I had some difficulties with the window slicer and occasionally with the keyboard inputs (in particular with backspace).

Christos Glymidakis
Christos Glymidakis

This was the fourth course I beta tested for this platform, it takes time to get used to this platform. Its great, once you get used to it.

Surendra Tanwar
Surendra Tanwar

This project was great! In a future project, I'd love to learn how you might deal with missing values or work with a data set that isn't so clean.

Krista Baker
Krista Baker

This is my 2nd rhyme course. Although engaging with the material is outstanding, it would be useful to have key terms (e.g. callback) listed to learn prior or during.

Paul Kubicz
Paul Kubicz
Amit Yadav

About the Host (Amit Yadav)


I am a machine learning engineer with focus in computer vision and sequence modelling for automated signal processing using deep learning techniques. My previous experiences include leading chatbot development for a large corporation.



Frequently Asked Questions


In Rhyme, all projects are completely hands-on. You don't just passively watch someone else. You use the software directly while following the host's (Amit Yadav) instructions. Using the software is the only way to achieve mastery. With the "Live Guide" option, you can ask for help and get immediate response.
Nothing! Just join through your web browser. Your host (Amit Yadav) has already installed all required software and configured all data.
Absolutely! Your host (Amit Yadav) has provided this session completely free of cost!
You can go to https://rhyme.com, sign up for free, and follow this visual guide How to use Rhyme to create your own projects. If you have custom needs or company-specific environment, please email us at help@rhyme.com
Absolutely. We offer Rhyme for workgroups as well larger departments and companies. Universities, academies, and bootcamps can also buy Rhyme for their settings. You can select projects and trainings that are mission critical for you and, as well, author your own that reflect your own needs and tech environments. Please email us at help@rhyme.com
Rhyme strives to ensure that visual instructions are helpful for reading impairments. The Rhyme interface has features like resolution and zoom that will be helpful for visual impairments. And, we are currently developing a close-caption functionality to help with hearing impairments. Most of the accessibility options of the cloud desktop's operating system or the specific application can also be used in Rhyme. If you have questions related to accessibility, please email us at accessibility@rhyme.com
We started with windows and linux cloud desktops because they have the most flexibility in teaching any software (desktop or web). However, web applications like Salesforce can run directly through a virtual browser. And, others like Jupyter and RStudio can run on containers and be accessed by virtual browsers. We are currently working on such features where such web applications won't need to run through cloud desktops. But, the rest of the Rhyme learning, authoring, and monitoring interfaces will remain the same.
Please email us at help@rhyme.com and we'll respond to you within one business day.

Ready to join this 48 minutes session for free?