Outliers and Influence

Drag one point around and watch a least-squares line follow it. Twenty-four rows say one thing; the twenty-fifth overrules them.

Overview

Drag it

The chart holds twenty-four points along a clear upward line, plus one highlighted point you can move. The dashed line is the least-squares fit without it. The solid line is the fit with it.

Drag the point straight up. The solid line rotates. Drag it to the far right and up, and the line follows it much further. The readout reports both slopes and the percentage difference between them, and it doesn't take much to change the answer by tens of per cent.

Twenty-four rows are saying one thing. The twenty-fifth overrules them.

Outliers and Influence

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

Least squares minimises squared error, so a point twice as far off pulls four times as hard.
An outlier far along the x axis has high leverage: it sits at the end of the lever and moves the line most.
A point can be extreme and correct. Deleting it because it is inconvenient is how findings stop being true.
Trees, medians and quantile regression are robust to outliers. Means, least squares and standard deviations are not.

Outliers and Influence

One row out of twenty-five, and the reason it can decide your answer.

Why squaring does this

Least squares chooses the line cutting the sum of squared residuals. Squaring is what makes a single point so powerful: a point twice as far from the line adds four times the fine, and one ten times as far adds a hundred times.

The fit is so willing to move a long way to reduce one large residual, even at the cost of small grows across every other point. That isn't a bug in the setup. It's what the goal function asks for.

Hat values: where it sits matters as much as how far off it is

Drag the point up while keeping it near the middle of the x range, then drag it up while keeping it at the far right. The second spot moves the line much more.

That difference is the hat value. A regression line pivots roughly about the mean of x, so a point near that mean is close to the pivot and has little turning effect no matter how far off it is vertically. A point at the extreme of x sits at the end of a long lever.

The gap is worth having in three words:

  • Outlier — unusual in y, a large residual.
  • High hat value — unusual in x, far from the pivot.
  • Influential — both, so dropping it changes the model. This is the one that matters, and Cook's distance is the standard way to measure it.

A point with a high hat value that happens to lie on the trend is harmless. A moderate outlier in the middle is harmless. The combination isn't.

Before you remove anything

The temptation is to delete the point. Resist it long enough to ask which of three things it's.

An error. A misplaced decimal, a sensor fault, a unit mix-up, a placeholder like 999 or −1 meaning "unknown". Fix it or drop it, and record that you did.

A different group. The row is correct but doesn't belong to the question — a wholesale order in a table of retail purchases. Exclude it and say so, or model the groups apart.

A real, extreme member of the group. The row is correct and belongs. This one you keep. Dropping genuine extremes because they're inconvenient is how a result stops showing the world, and it's much more common than deliberate fraud.

If you can't tell which, report the analysis both ways. A conclusion that lives the point and a conclusion that depends on it are different findings, and the reader is entitled to know which they've.

Ways to be less fragile

Solid loss. Huber loss is squared for small residuals and linear for large ones, so a distant point pulls hard but not as n² hard. RANSAC fits on random subsets and keeps the consensus.

Quantile regression. Models the median rather than the mean, and the median doesn't move when one point is dragged to infinity.

Winsorising. Clip values at, say, the 1st and 99th percentiles. Keeps the row, caps its sway.

Use a model that doesn't care. Trees split on order, not on distance, so a value of a million and a value of a thousand are the same split if nothing lies between them.

Transform. A log transform on a skewed plus column often turns "outliers" into plain members of a normal-shaped spread, which is often a sign the column was on the wrong scale.

Why position matters as much as distance

The reason one far-off point wrecks a fit and another leaves it alone is the hat value, and squared error is what makes it bite. Least squares cuts the *sum of squared* residuals, so a point twice as far off adds four times the fine and one ten times as far adds a hundred times. The line will travel a long way to reduce a single large residual. But a regression line pivots roughly about the mean of x. So How far a point sits along x decides how much turning force its vertical error applies:

the odd pointeffect on the slope
large residual, near the middle of xsmall — close to the pivot
large residual, at the extreme of xlarge — the end of a long lever

That gives three distinct things worth separating: an outlier is unusual in y, a high hat value is unusual in x, and only their combination — influential — really moves the model. This is what Cook's distance measures. A point with a high hat value sitting on the trend is harmless. A mid-range outlier is harmless. The far-right outlier is the one that quietly rewrites the answer. Which is also why "delete any of it beyond three standard deviations" is self-defeating: the outlier has already inflated the standard deviation the rule depends on.

Where it goes wrong with Outliers and Influence

Deleting by rule. "Beyond three standard deviations" uses the standard deviation, which the outlier itself has already inflated.

Treating placeholders as data. 999 for unknown age, −1 for missing. These aren't outliers. They're missing values wearing a number.

Dropping points until the model fits. At that stage the model shows the pick, not the effect.

Checking only y. Points with high hat values can be plain in y and still dominate the fit.

Questions people ask about Outliers and Influence

Is every outlier a problem? No. An outlier is an unusual value, and it matters only if it changes the fit. A point that sits on the trend line is harmless.

What is the difference between an outlier and an influential point? An outlier has an unusual response given its inputs, while an influential point changes the fitted model when removed. Points far from the other inputs are the usual cause of influence.

How do I measure influence? Cook's distance combines residual size and distance from the other inputs in one number. A common rule of thumb flags values above 4/n for a closer look.

Should I delete outliers? Only after checking whether they are errors. If the value is real, removing it hides something true about your data, so consider a different model or transform instead.

What can I do besides removing them? Use a loss that is less sensitive to large errors, such as Huber or quantile regression. Or transform the target, or use median-based statistics.

Why does squared error make outliers worse? Squaring makes one large residual count far more than many small ones, so the fit bends towards the extreme point.

An outlier and an influential point are not the same thing

One far-out row can leave a fit untouched while another moves it fully. The difference is the hat value, and it is computable.

example_01.pyscikit-learn
Output

The next block computes hat values and Cook's distance to show how influence is measured.

example_02.pyscikit-learn
Output

The next block shows how resistant estimators handle the same outlier.

example_03.pyscikit-learn
Output

Check yourself

0 of 3

Answer without scrolling back up.

  1. Why does least squares react so strongly to a single distant point?

  2. What makes a point 'influential' rather than merely an outlier?

  3. What is wrong with removing anything beyond three standard deviations?

Cheat sheet

Outliers and Influence

Move one data point and watch the regression line follow it. Use Cook's distance and hat values to find the rows that control your model.

MACHINE LEARNING · vizlearn.in/machine_learning/outliers_and_influence.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.