Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Outliers and anomalies

  • The terms outliers and anomalies can sometimes be synonymous, but have different origins in data analysis.

  • An outlier in statistics is typically defined with respect to some known (or assumed) distribution and its statistics.

    • An outlier in a dataset does not have the same properties as the majority of observations or is more extreme in some sense.

    • An outlier in a model is either extreme in the data distribution or its predictions deviate more from the truth than the typical observation does.

  • An anomaly in machine learning is typically an observation that deviates from the the majority of observations or from the samples in its local neighbourhood.

    • There are fewer assumptions about distributions in machine learning than statistics.

Outliers for 1D data

  • A simple representation of data is the box (and whiskers) plot.

  • A common choice is to stop the whiskers at 1.5 IQR, where IQR = 75th percentile - 25th percentile.

<Figure size 640x480 with 1 Axes>

Boxplot properties

... assuming normal distributed data.

<Figure size 500x300 with 1 Axes>
Upper whisker: 2.698 standard deviations
Probability of being outside whiskers: 1.993%

Outliers in models

  • An outlier in the input data, X, will influence some models more than a central point would do.

    • In regression (Ordinary Least Squares), these are called high leverage points.
      OLS for X~=[1 X]\tilde{X} = [1 ~ X]:
      X~β=X~(X~′X~)−1X~′Y\tilde{X}\beta = \tilde{X} (\tilde{X}'\tilde{X})^{-1} \tilde{X}' Y
      Leverage hiih_{ii} from the diagonal of H=X~(X~′X~)−1X~′H = \tilde{X} (\tilde{X}'\tilde{X})^{-1} \tilde{X}'.

  • An outlier in the response, y, can be caused by a model of wrong complexity.

    • Too complex: Overfitting, bad generalisation.

    • Too simple: Does not fit well enough to describe important variation.

Handling outliers/anomalies

  • An outier can be caused by errors in measurements, faulty registration or random variation.

    • Or it can be deviating because of unexplained, but important, phenomena.

  • Depending on the case at hand, there are several options for handling outliers:

    • Remove the outlying measurement - results in missing data.

    • Impute the values of the outlier, i.e., replace it by something inlying, e.g., average over nearest neighbours (pre-processing section).

    • Use a smoothed value according to the local trend (Noise reduction).

    • For visualisation, present a smoothed signal, but show the underlying variation as a shadow or error region (shown below).

    • Sound an alarm, e.g., a warning sign, alerting an operator to potential problems (dashboard section).

<Figure size 700x300 with 1 Axes>