Level 2 · Module 10 · 10 minutes
Linear regression: fitting a simple line to numbers
- Explain what a linear regression model is fitting and how prediction works.
- Describe the main strengths and trade-offs of a line-shaped model.
- Explain why regression is judged with error sizes rather than a correct-answer share.
Linear regression predicts a number by fitting a straight line to past examples. It is one of the oldest and easiest machine learning methods, and it stays popular because its answer can be read and explained. It assumes the pattern is roughly a line: when one feature rises, the prediction rises or falls by a steady amount.
What the line means
A straight line is described by where it starts and how steeply it rises. Training chooses those two values so the line sits as close as it can to the known examples. Closeness is judged by the size of the misses: for each past case, compare the predicted number with the real number, then prefer the line with the smallest average miss.
Prediction is then simple. Take the features for a new case, read the value the line gives, and report it. This is why regression is often chosen for forecasts such as demand, travel time or amount spent, where a rough number is more useful than a category.
Strengths and trade-offs
- It is transparent: the effect of each feature is visible as the slope.
- It is fast and needs relatively little computing power.
- It can be wrong when the true pattern is curved or changes sharply.
- A few outliers can pull the line badly, because every miss counts.
- It cannot easily capture combinations of features unless you add them as new columns.
The trade-off is clear: a simple, explainable model in exchange for missing complicated patterns. On small tidy tables it is often a strong first choice; on rich images or long text it is not enough.
Judge it with errors, not confidence
Because the answer is a number, a share of correct answers does not fit. Report the average size of the misses and the worst misses, and compare against a plain baseline such as always predicting the average. A prediction is an estimate with a range of likely error, not a promise, and a line fitted on a few rows deserves particular caution.
A teaching picture versus real training
A two-axis chart with a hand-drawn line is a simplified teaching picture of regression. Real training software fits many features at once on a full dataset and is measured on held-out rows. Commercial systems often keep a line like this as an explainable baseline against which fancier models are judged. This lesson trains nothing; the line you draw is practice.
Common misconception
A regression model's output is a certain answer because the fitted line is exact. The line is a best fit to noisy examples, not a law. Every prediction carries a likely error, and outlying cases or curved patterns can make that error large. Report the average miss and the worst miss, and treat the number as an estimate.
Guided practice
On paper, make a small table with hours of sun and plant growth for five days. Draw the best straight line by eye, predict the growth for a sixth day, and mark which point pulls the line most strongly. Then write one case where a curve would fit better than a line. No software is used and no model is trained.
Knowledge check
Independent practice
Write a short example from your own work or daily life and decide whether it is AI, ordinary software or a mixture. Then explain why. Save it in your notes; no account is required.
Last reviewed: · Report a problem