The Line of Best Fit Isn't "Best" — It's a Decision What I wish someone had told me before I ran my first regression model.
![]() |
| Same data. Different definition of "best." Different line." |
Here's something that took me longer than I'd like to admit to figure out about linear regression.
That line through your scatter plot — the one everyone calls the "line of best fit" — isn't objectively the best anything. It's the best fit for one very specific definition of the word "best."
Swap that definition, and you get a completely different line. Equally valid mathematically. Just built on a different set of assumptions.
Once I understood that, I started looking at every machine learning model differently.
What Everyone Gets Taught (And What Gets Left Out)
The standard introduction to linear regression goes something like this: draw a line through your data that minimises the total error between your predictions and the actual values. Square those errors, add them up, minimise the sum. Done.
This is Ordinary Least Squares (OLS) — the engine behind most introductory regression models, and one of the most well-understood methods in all of statistics.
But here's the question that almost never gets asked in that introductory lesson: why squared errors specifically?
The Hidden Decision Inside the Formula
When you square your errors instead of, say, taking their absolute values, something specific happens to your model's behaviour.
Squaring is not neutral. It amplifies large errors disproportionately — an error of 20 doesn't just become twice as costly as an error of 10, it becomes four times as costly. An error of 100 becomes one hundred times as costly as an error of 10.
The consequence: your model becomes heavily influenced by outliers. Data points sitting far from the main cluster pull the line toward them with outsized force, because their large errors — once squared — dominate the entire calculation.
This is a design decision baked into the algorithm. Whoever chose to minimise squared errors was implicitly deciding: large mistakes matter much more than small ones. That's often a reasonable position. But it's a position, not a mathematical law.
A Different Choice: Mean Absolute Error
Mean Absolute Error (MAE) takes the absolute value of each error instead of squaring it. An error of 20 is simply twice as costly as an error of 10 — proportional, intuitive, straightforward.
The result is a model that treats outliers more evenly. It doesn't get pulled toward unusual data points with the same force that OLS does.
Technically speaking:
- OLS finds the conditional mean — the line passing through the average of y for every value of x
- MAE finds the conditional median — the line passing through the middle value of y for every value of x
Neither is universally better. They answer slightly different questions. The right choice depends entirely on your data and what you're trying to do with the model.
What I Saw in a Real Dataset
I ran into this exact issue working through the Housing Dataset — predicting house sale prices across hundreds of properties with dozens of features.
The OLS model performed well on typical houses. But a small number of high-value outlier properties — unusual homes with sale prices far above the typical range — were pulling the regression line in ways that quietly hurt performance everywhere else. Large squared errors from those few properties were carrying a weight in the loss function that the raw numbers didn't justify.
It's the kind of thing you don't notice if you're only looking at your overall R² score. You have to dig into the residuals, look at where your model is struggling, and ask why.
The answer, in this case, traced all the way back to the choice of loss function.
The Real Lesson Underneath All of This
Loss functions are choices. Assumptions are choices. Even the word "best" in "best fit" is a choice — best for a specific metric, under specific conditions, for a specific purpose.
Every machine learning algorithm you will ever use has decisions like this buried inside it. Decisions made by researchers and practitioners before you, embedded into the method, and handed down as defaults.
The job of a thoughtful data scientist isn't just to run the default and report the output. It's to understand what choices were made, why they were made, and when a different choice might serve your problem better.
Linear regression, understood at this level, isn't just a simple algorithm. It's a masterclass in how to ask better questions about every model that follows it.
The Short Version
OLS minimizes squared errors — a deliberate design choice that makes your model sensitive to outliers. MAE minimizes absolute errors — a different choice, more robust to unusual data points. The "line of best fit" is only best for the definition of "best" embedded in your loss function. Knowing that gives you the power to question it — and change it when your data calls for something different.
What's Next
This is Notebook #2 in an ongoing series working through data science from the foundations up — not as a textbook would, but as I'm actually learning and applying it.
The next notebook could go deeper into regression, shift to something entirely different, or revisit something I touched on too briefly here. A working notebook follows the thinking, not a fixed syllabus.
Follow along so you don't miss wherever it goes next.
If this sparked a question or you see something worth pushing back on, drop it in the comments. This is a working notebook — disagreement and discussion are part of the process.
The code behind the Housing project referenced in this post is available on my GitHub — github.com/dshah-ds. Feel free to explore, fork, or reach out if you have questions about the implementation.

Comments
Post a Comment