liveBook · Manning

Distance

As explained in Outlier Detection in Python

A function that quantifies dissimilarity or separation between observations in a data space.

Distance quantifies how separated or dissimilar two observations are. Outlier detectors often compare a record with other records: being far from most can indicate an outlier, but distance becomes less reliable as dimensionality grows. section 3.1.3

Figure 3.1 A scatterplot of features A and B (left) and scatterplot of features C and D (right). A point (drawn as a star) is shown that is an outlier in A, though is normal in features B, C, and D. Its distance to the other points in 4D space will separate it well from the other points, but this could fail in much higher dimensional spaces.

The figure contrasts a point that stands out in one feature but is ordinary in others with the risk that added dimensions make its distance less distinctive. section 3.1.3

Distance choices and preparation affect what a detector treats as unusual:

  • Euclidean, Manhattan, Mahalanobis, and other measures can produce different distances; the useful choice depends on the project. section 9.7
  • Scale numeric features to comparable ranges so larger-valued features do not dominate distance calculations. section 3.2
  • For mixed data, combine numeric and categorical distances with a weight; one-hot encoding can also affect distances by giving categorical features more influence. section 9.7.4 section 9.4.1
  • In high-dimensional data, distances can become nearly equal; removing features or reducing dimensionality, such as with PCA, can help address this limitation. section 3.1.3

Comparing related time series

For air-quality measurements, scale PM2.5, PM10, and SO2, then calculate pairwise differences. Unusually large divergences can help flag times when one series departs from the others, though the flagged cases still need interpretation. section 17.2.9

How Outlier Detection in Python covers it

How deep it goes
Compares several distance measures and mixed-data weighting, while cautioning that high dimensionality can undermine distance-based detection.
Examples
Illustrates a four-dimensional point unusual in one feature and air-quality series compared through pairwise differences.
What it assumes
Requires comparable numeric features for common geometric methods; categorical features need encoding, while mixed data can use separately chosen measures.
What you can do after
Evaluate/understand it: compare distance measures and recognize when scaling, mixed-data choices, or dimensionality may affect results.
How it connects
Connects distance to outlier detection, feature scaling, dimensionality reduction, and categorical encoding.

Also explained in

Compare how 10 books explain distance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.