- [Instructor] Now that we have trained
and tested our model, let's use it.
Let's open up make_predictions.py.
You'll notice as we go through this example,
there are only a few lines of actual code
even though this file contains all the logic needed
to estimate the value of a house.
That's because all the logic
was created by the machine learning algorithm
and saved in our model.
We only need to load the model,
pass in house data, and run it.
First, let's load the gradient boosting model
that we trained earlier.
We just call joblib.load and pass in the file name.
Next we have a list of all the attributes
for the specific house that we want to value.
We need to create an array
with the same features in the exact same order
as the training data that we used to train our model.
That means the data here needs to reflect
any feature engineering changes we made.
So the fields we removed and the fields we added
with one hot encoding are reflected here.
I've already gone ahead
and defined all the parameters
for an imaginary house built in 2006,
including its basic features,
the type of garage it has,
and what city it's located in.
Next, we need to create an array of the homes to value.
Scikit-learn assumes that you want
to make predictions for multiple items at once,
so it expects an array of houses to value.
Since we only want to value one house right now,
we'll just put house_to_value by itself,
and then the array called homes_to_value.
To make a prediction for the data,
we call model.predict and pass in the array of features.
The result is an array containing
a price prediction for each house.
Since we just passed in one house,
we'll just grab the first prediction
by looking at index zero.
And then finally, we'll print out
the value that it predicted.
Let's go ahead and run this.
Right click and choose Run.
For this house, it predicts a price of $587,000.
But let's see what happens
if we change some of the attributes.
Let's go up and change the year built from 2006 to 1973.
Now let's rerun it and see how that changes the value.
Right click, Run, now we can see the value drop to $454,000.
It looks like the age of the house matters a lot.
Now what if we change some other attributes?
What if we say this house has an attached garage,
so we'll change it from attached and remove none,
and the garage has 400 square feet of space?
Now let's rerun it and see how that changes the value.
Now the value goes up to $499,000.
What about city?
Let's change the house's city and rerun.
Now the value of the house
drops significantly to $386,000.
It seems like location matters a lot to the value.
You can try adjusting any of these values yourself
to see how it affects the final price.
Now we have a complete working system.
If we replaced this script with a nice user interface,
we'd have a real product that's pretty cool.