Learn about the idea of regression.
- [Instructor] Before we dive into more complicated machine learning algorithms let's build the simplest program possible to estimate the value of a house based on its attributes. Open up simple_value_estimator.py. Here we have a function called estimate_home_value. The goal of this function is to estimate the price of a house based on its attributes. This function takes in two attributes to describe a house the size of the house in square feet and the number of bedrooms in the house. At the end of the function it returns the predicted value for the house. To predict the value for the house all we have to do is decide how much the size of the house and the number of bedrooms affects the final value of the house.
Let's start by assuming that any house no matter how small is worth at least $50,000 so we can start with $50,000 as the initial value estimate. Next, we have to decide how much the size of the house plays into the final value. I'm going to guess that every square foot is worth $92 so we can say that the value is now the current value plus the size in square feet times 92. Next, let's look at the bedrooms. It seems reasonable to assume that houses with more bedrooms are worth more than houses with fewer bedrooms.
For every bedroom I'm going to add, say, $10,000 in additional value. We'll say the value is now the value plus the number of bedrooms times 10,000. Finally, let's call this function by trying it on the real house we know costs $450,000. Down here we'll pass in 3800 square feet and five bedrooms. We can run this file by right clicking and choosing Run. It's worth pointing out there's also a keyboard shortcut for running a file but it might be different on your system. In my case, it's Control + Shift + F10.
It's also worth pointing out that if you click Run at the top here it runs the last file not necessarily the current file you're looking at so it's easier just to right click and choose run. Down here it will open the console and show us the output of our program. Our program predicted the house is worth $449,000. That's really close to the $450,000 value we expected. Our estimator is working pretty well. In this example, all we did was take each input value and multiply them by a fixed weight. The weight for size in square feet was 92 and the weight for number of bedrooms was 10,000.
In other words we're saying that the real value of the house is some combination of its size and the number of bedrooms it has. The weights tell us how much each of those factors in to the final calculation. The process of modeling the value of something with a set of fixed weights is called linear regression. It's one of the simplest machine learning algorithms but with machine learning the computer comes up with the weights by itself by looking up the training data. In the next video we'll learn how the computer can find the best weights on its own.
- Setting up the development environment
- Building a simple home value estimator
- Finding the best weights automatically
- Working with large data sets efficiently
- Training a supervised machine learning model
- Exploring a home value data set
- Deciding how much data is needed
- Preparing the features
- Training the value estimator
- Measuring accuracy with mean absolute error
- Improving a system
- Using the machine learning model to make predictions