Concept 1

The line equation

Linear regression is often the first real machine learning algorithm students learn because it turns a simple idea into a useful prediction engine: learn a relationship from past data, then predict a future numeric value.

Why linear regression matters in ML

In supervised machine learning, we train a model using examples where both the input and the correct output are already known. Linear regression is used when the output is a continuous number, such as price, salary, revenue, demand, marks, temperature, delivery time, or sales.

The exciting part is that the model does not memorize answers. It learns a pattern: how much the output usually changes when the input changes. That makes it a foundation for understanding more advanced ML ideas like loss functions, optimization, feature importance, regularization, and even neural-network training.

Business forecasting

Predict sales from advertising spend, forecast demand from historical orders, or estimate revenue from marketing activity.

Pricing and salary

Estimate house prices from area and location, or predict salary from experience, skills, and city.

Operations and planning

Estimate delivery time, ride fare, inventory needs, energy usage, or customer lifetime value.

Key idea: linear regression introduces the basic loop of machine learning: predict, measure error, improve, and interpret.

Opening interaction

Where have you already seen a numeric prediction in real life?

Collect 5-6 answers on the board, then classify them as regression or not regression. Good examples: cab fare, house price, salary, exam marks, delivery time, stock price, monthly sales.

Core formula

\[\hat{y} = mx + c\]

In ML notation, the same idea is usually written as:

\[\hat{y} = \beta_0 + \beta_1x\]

When discussing real data, add an error term:

\[y = \beta_0 + \beta_1x + \varepsilon\]
  • y: actual target value.
  • y_hat: predicted target value.
  • b0: intercept, the base prediction when x is 0.
  • b1: slope/coefficient, the change in prediction for a one-unit increase in x.
  • e: residual, the part the line failed to explain.

Quick check

If salary = 30000 + 8000 * years_experience, what is the predicted salary for 3 years?

What does 8000 mean in plain English?

intercept b0 slope one unit change in x

Slope is the rate of change. If x increases by 1, prediction changes by b1.

Examples

ProblemxyCoefficient meaning
Salary predictionYears of experienceSalaryExtra salary expected for one more year of experience.
House priceArea in square feetPriceExtra price expected for one more square foot.
AdvertisingTV ad spendSalesExtra sales expected for one more unit of TV spend.
Important wording: linear regression is not saying reality is perfectly linear. It is saying a straight line is a useful first approximation.

Think-pair-share

Can you name one case where a straight line is a bad approximation?

Takeaway: model choice depends on the pattern in data. Examples: age vs medical risk, price vs demand, experience vs salary at senior levels.

Back to overview Next: Errors and cost