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.
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
In ML notation, the same idea is usually written as:
When discussing real data, add an error term:
- 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?
Slope is the rate of change. If x increases by 1, prediction changes by b1.
Examples
| Problem | x | y | Coefficient meaning |
|---|---|---|---|
| Salary prediction | Years of experience | Salary | Extra salary expected for one more year of experience. |
| House price | Area in square feet | Price | Extra price expected for one more square foot. |
| Advertising | TV ad spend | Sales | Extra sales expected for one more unit of TV spend. |
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.