Your First Day at HomeWorth
A model in six lines of code.
Imagine your first day at a new job. The company is called HomeWorth, and it has one problem. Every morning, people ask, what is my house worth? Right now, one tired expert answers by hand, and it takes three days. Your boss looks at you and says, can you teach a computer to do this? Over this course, that is exactly what you will do.

- Your new job: HomeWorth
- One expert, three days per answer
- Your mission: teach a computer
A model in six lines
Before we learn a single definition, let's see the magic. This is a complete machine learning program. First, we load real data, about twenty thousand homes in California. We split it into X, the facts about each house, and y, the prices. Then we create a model, and call fit. That one word is the learning. Now we hand it a house, and ask for a price. Run it, and the computer gives an estimate close to the real price. Nobody wrote a rule about prices. It worked them out.
from sklearn.datasets import fetch_california_housing
from sklearn.linear_model import LinearRegression
data = fetch_california_housing()
X, y = data.data, data.target
model = LinearRegression()
model.fit(X, y)
house = X[0].reshape(1, -1)
prediction = model.predict(house)[0]
print(f"Predicted price: ${prediction * 100000:,.0f}")
print(f"Actual price: ${y[0] * 100000:,.0f}")Predicted price: $413,165 Actual price: $452,600
What just happened
So what did fit really do? Think of each dot as a house, with its size along the bottom, and its price going up. The model starts with a terrible guess, a line that fits nothing. It measures how wrong it is. Then it nudges the line, just a little, and measures again. Watch the error fall. After enough small steps, the line settles through the middle of the data. That is learning. Not magic. Just measuring mistakes, and correcting them.
Summary
You just trained your first model, on your first day. You also saw the secret, learning means reducing mistakes, step by step. But your boss has a harder question. What is machine learning, really, and when should you use it? That is next.
Key takeaways- You trained a real model
- fit means learn from data
- Learning means reducing mistakes