Try It Yourself
You have seen the code and understood how it works. Now stop reading and change the program yourself.
The goal is to change the data, run the program, observe what happens, and understand why the prediction changes.
Start With This Code
Use the same program from the previous topics.
# Training data
sizes = [800, 1000, 1200, 1500]
prices = [300000, 400000, 500000, 650000]
# Learn a simple relationship
price_per_sqft = sum(prices) / sum(sizes)
# New house
new_house_size = 1400
# Make a prediction
predicted_price = new_house_size * price_per_sqft
print("Predicted price:", predicted_price)
Change the New House Size
Find this line:
new_house_size = 1400
Change it to:
new_house_size = 1800
Now run the program and check your answer.
python house_price_prediction.py
The new house is larger, so the prediction
changes according to the relationship stored
in price_per_sqft.
Try a Smaller House
Now change the input to:
new_house_size = 600
Run the program and compare the results.
The learned relationship stays the same. Only the new input changed.
Add Another Training Example
Our current training data contains four examples.
sizes = [800, 1000, 1200, 1500]
prices = [300000, 400000, 500000, 650000]
Add an 1,800 sq ft house with a price of $750,000.
sizes = [800, 1000, 1200, 1500, 1800]
prices = [300000, 400000, 500000, 650000, 750000]
Run the program again and compare the result with the previous version.
Change a Training Price
Now make one training example more expensive.
Change:
prices = [300000, 400000, 500000, 650000]
to:
prices = [300000, 400000, 600000, 650000]
Run the program and compare the new result with the previous result.
Changing the training data changes the learned relationship, which can change future predictions.
Predict Multiple Houses
Instead of predicting one house, try several.
new_house_size = 900
predicted_price = new_house_size * price_per_sqft
print("900 sq ft:", predicted_price)
new_house_size = 1400
predicted_price = new_house_size * price_per_sqft
print("1400 sq ft:", predicted_price)
new_house_size = 2000
predicted_price = new_house_size * price_per_sqft
print("2000 sq ft:", predicted_price)
Find a Problem With Our Model
Consider these two houses:
City center
Rural area
No.
Both houses have the same size, and our program only knows about house size.
A model can only use the information we give it. If location is not included in the data, our simple program cannot use location when making its prediction.
What If We Gave the Model More Information?
Instead of giving the model only house size, we could provide additional information such as:
Now the model has more information that could potentially help it make a better prediction.
We will study features properly in a later lesson.
Build Your Own Version
Start with the original program and make these changes yourself.
Choose its size and price.
Try predicting a different house size.
Try at least three different house sizes.
Write down why the prediction changed.
What Should You Understand Now?
Training data can influence the learned relationship.
New input is passed through the learned relationship to produce a prediction.
Changing the input can change the prediction.
Changing training data can also change future predictions.
The model cannot use information that was never provided to it.
Don't just run the code. Experiment with it.
Machine Learning becomes easier to understand when you change the data, observe the output, and ask why the result changed.
You built and experimented with a simple prediction system.
You started with training examples, created a simple learned relationship, and used it to make predictions for new inputs.