MACHINE LEARNING • LESSON 1 • BUILD IT

Try It Yourself

You have seen the code and understood how it works. Now stop reading and change the program yourself.

The goal is not to get the "right" answer.

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.

Python
# 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)
EXERCISE 01

Change the New House Size

Find this line:

new_house_size = 1400

Change it to:

new_house_size = 1800
THINK BEFORE RUNNING Will the predicted price increase or decrease?

Now run the program and check your answer.

python house_price_prediction.py
WHY?

The new house is larger, so the prediction changes according to the relationship stored in price_per_sqft.

EXERCISE 02

Try a Smaller House

Now change the input to:

new_house_size = 600
PREDICT FIRST Should the predicted price be higher or lower than the prediction for 1,800 sq ft?

Run the program and compare the results.

OBSERVATION Changing the input changes the prediction.

The learned relationship stays the same. Only the new input changed.

EXERCISE 03

Add Another Training Example

Our current training data contains four examples.

Python
sizes = [800, 1000, 1200, 1500]

prices = [300000, 400000, 500000, 650000]

Add an 1,800 sq ft house with a price of $750,000.

Python
sizes = [800, 1000, 1200, 1500, 1800]

prices = [300000, 400000, 500000, 650000, 750000]
THINK What do you expect to happen to price_per_sqft?

Run the program again and compare the result with the previous version.

EXERCISE 04

Change a Training Price

Now make one training example more expensive.

Change:

prices = [300000, 400000, 500000, 650000]

to:

prices = [300000, 400000, 600000, 650000]
QUESTION What happens to the prediction for a 1,400 sq ft house?

Run the program and compare the new result with the previous result.

This is the important lesson.

Changing the training data changes the learned relationship, which can change future predictions.

EXERCISE 05

Predict Multiple Houses

Instead of predicting one house, try several.

Python
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)
OBSERVE How does the prediction change as house size increases?
EXERCISE 06

Find a Problem With Our Model

Consider these two houses:

HOUSE A 1,400 sq ft

City center

HOUSE B 1,400 sq ft

Rural area

THINK Will our current program give them different prices?

No.

Both houses have the same size, and our program only knows about house size.

This exposes an important limitation.

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:

Size 1,400 sq ft
Bedrooms 3
Location City center
Age 5 years

Now the model has more information that could potentially help it make a better prediction.

COMING LATER These input values are called features.

We will study features properly in a later lesson.

FINAL CHALLENGE

Build Your Own Version

Start with the original program and make these changes yourself.

01 Add another house

Choose its size and price.

02 Change the new input

Try predicting a different house size.

03 Compare predictions

Try at least three different house sizes.

04 Explain the result

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.

KEY TAKEAWAY

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.

BUILD IT • COMPLETE

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.

NEXT SECTION

What Happens When Data Changes?

You changed the data and saw that predictions can change. Next, we'll understand why this happens and what it tells us about Machine Learning models.