Quant Memo
Core

Local Outlier Factor

Local Outlier Factor flags a point as anomalous when it is much less densely surrounded by neighbors than its own neighbors are, catching outliers that live inside a locally sparse region even if the overall dataset is dense elsewhere.

Local Outlier Factor (LOF) scores how anomalous a point is by comparing the local density around it to the local density around its neighbors, rather than comparing it to the dataset's overall average density. This local, relative comparison is what lets LOF catch outliers that would be missed by a method using one fixed global threshold.

LOF compares each point's density (how tightly packed its nearest neighbors are) against the densities of those same neighbors' neighborhoods; a point sitting in a much sparser neighborhood than its neighbors gets a high LOF score, flagging it as a local outlier even if denser regions exist elsewhere in the data.

Why "local" matters

A dataset can have two clusters, one dense and tightly packed, one loose and spread out. A point on the edge of the loose cluster might still be closer, in raw distance, to the dense cluster's outer edge than to its own cluster's typical spacing — a global density threshold could wrongly flag it. LOF instead asks "is this point unusually sparse relative to its own neighborhood," which correctly treats it as normal for its (looser) cluster.

Worked example

Point X has an average distance to its 5 nearest neighbors of 4.0. Those same 5 neighbors, however, are on average only 1.0 apart from their own nearest neighbors — X's neighborhood is four times sparser than the neighborhood its neighbors enjoy. The resulting LOF score comes out well above 1 (roughly 4, in this simplified telling), flagging X as a local outlier, whereas a point with density matching its neighbors would score near 1, i.e. normal.

LOF scores are only meaningful in comparison to each other, not against some fixed cutoff like "flag anything above 2" — the right threshold depends entirely on the dataset, so it usually needs to be calibrated by looking at the score distribution rather than picked in advance.

Related concepts

Practice in interviews

Further reading

  • Breunig et al., 'LOF: Identifying Density-Based Local Outliers'
ShareTwitterLinkedIn