- Introduced by
- Breunig, M. M.; Kriegel, H.-P.; Ng, R. T.; Sander, J.
- Year
- 2000
- Type
- Density-based anomaly detection (unsupervised)
What does it do?
Local Outlier Factor (LOF) is an unsupervised anomaly detection method introduced by Breunig, Kriegel, Ng, and Sander in 2000.
Instead of labelling each point as an outlier or not, it assigns a continuous score that compares the density around a point with the density around its neighbors. This lets it flag points that are isolated relative to their own neighborhood, even when a single global distance threshold would not single them out. LOF is often described as a density-based method, but it can also be viewed as a distance normalized by the average local data density, the framing used in the 2015 data mining text in the library (Section 8.5.2.1).
The intuition behind the method
Imagine a city map where most people live in dense urban districts. A house sitting alone in the countryside is obviously isolated. But LOF goes further: it can also flag a house that sits in a moderately dense suburb when all its immediate neighbors are packed into an even denser cluster. Instead of asking 'is this point far from everything?', LOF asks 'is this point's neighborhood much sparser than the neighborhoods of its own neighbors?' A point whose neighbors all live more tightly together than the point itself gets a high LOF score — signaling that it is a local outlier even if globally it is not in an empty region.
History
LOF was introduced at the ACM SIGMOD 2000 International Conference on Management of Data by Markus M. Breunig, Hans-Peter Kriegel, Raymond T. Ng, and Jörg Sander. The authors argued that existing outlier work treated being an outlier as a binary property, and proposed instead assigning each object a degree of being an outlier, which they called the local outlier factor. Later work has extended the idea, with variants named in this entry including LoOP (local outlier probabilities), LOCI, and COF.
When to use it
Choose LOF when the features are numeric or can be given a meaningful distance, no labelled anomalies are available, and normal points form groups of differing density. In that setting a single global distance cutoff tends either to miss anomalies in sparse areas or to flag ordinary points in sparse but consistent groups. Typical use is exploratory screening, such as the tasks listed under applications. The core assumptions are that inliers form locally cohesive neighborhoods and that the chosen distance metric is meaningful for the features. Avoid LOF on high-dimensional data unless dimensionality is reduced first, because distances become less discriminative there. It is also a poor fit when new observations must be scored without keeping the training data, since each LOF score depends on stored training neighborhoods.
Limitations and considerations
- Computing every k-neighborhood requires distances between points. A naive implementation scales poorly as the number of points grows, and spatial indexing tends to help less as dimensionality increases.
- The result depends on k: a small k makes scores noisy, while a large k averages over the local structure that the score is meant to capture.
- Distances lose contrast in high-dimensional spaces, so the density comparison becomes unreliable unless dimensionality is reduced or features are selected.
- Scores are computed against the stored training set, and there is no compact fitted model to apply to new points.
- The score has no fixed upper bound, so scores from different datasets or different values of k are not directly comparable.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Captures anomalies defined relative to local density, which a global distance threshold cannot do when clusters differ in density.
- Returns a continuous score for each point, so the cutoff can be chosen after inspecting the score distribution rather than fixed in advance.
- Needs no labelled anomaly examples; the score is computed from the unlabelled feature matrix alone.
- Works with any distance function defined on the features, so non-Euclidean metrics can be used.
Applications
- Fraud detection in financial transactions where fraudulent activity creates locally sparse patterns.
- Network intrusion detection by flagging traffic records whose local neighborhood is much sparser than its surroundings.
- Manufacturing quality control to identify defective items in sensor-rich production data.
- Medical anomaly screening — detecting unusual patient profiles relative to similar patient cohorts.
- Spatial anomaly detection in geographic and environmental data with heterogeneous density.
How it works
How it works
For each point p the algorithm first computes the k-distance: the distance to p's k-th nearest neighbor. This defines the reach of p's local neighborhood. All points within that distance form the k-neighborhood N_k(p). The choice of k controls the scale at which locality is assessed — small k captures fine-grained local structure, larger k smooths over it.
Formula
k\text{-dist}(p) = \text{distance to the } k\text{-th nearest neighbor of } pThe reachability distance from p to a neighbor o is defined as the maximum of the k-distance of o and the actual Euclidean (or other metric) distance between p and o. This smoothing prevents instability when two points are extremely close together: it replaces tiny distances with the broader footprint of o's own neighborhood, making density estimates more robust.
Formula
\text{reach-dist}_k(p, o) = \max\{k\text{-dist}(o),\, d(p, o)\}The local reachability density of p (lrd) is the inverse of the average reachability distance from p to all its k neighbors. A point surrounded by tightly packed neighbors has a small average reachability distance, and therefore a high lrd. A point in a sparse region has a large average reachability distance and a low lrd.
Formula
\text{lrd}_k(p) = \left(\frac{\sum_{o \in N_k(p)} \text{reach-dist}_k(p,o)}{|N_k(p)|}\right)^{-1}The LOF score of p is the average ratio of its neighbors' lrd values to p's own lrd. If p's neighbors all have substantially higher lrd than p itself — meaning they live in denser subregions — the ratio exceeds 1, indicating that p is a local outlier. A score near 1 indicates that p has roughly the same density as its surroundings. Scores much greater than 1 flag increasingly anomalous points. This locality-aware comparison is what distinguishes LOF from distance-only methods.
Formula
\text{LOF}_k(p) = \frac{\sum_{o \in N_k(p)} \frac{\text{lrd}_k(o)}{\text{lrd}_k(p)}}{|N_k(p)|}Common pitfalls
- Computing distances on raw features with different units lets high-variance features dominate. LOF is not scale-invariant, so features should be standardized before distances are computed.
- Using a single value of k without checking others. The set of flagged points can change substantially with k, so several values should be compared.
- Treating the LOF score as a probability. It is a ratio of local densities and has no calibrated probabilistic interpretation.
- Including many identical or near-identical points. If a point's neighbors coincide with it, its average reachability distance can be zero, so its local reachability density becomes undefined or infinite. Such duplicates should be inspected or removed first.
- Choosing a cutoff from a fixed rule of thumb without examining the score distribution of the dataset at hand.
- Setting k below the size of a tight group of outliers. The group then forms its own dense neighborhood, so its members can receive scores close to 1 and appear normal.
Frequently asked questions
How do I choose the right value of k?
There is no universally correct k, and the supplied sources give no default range for it. k must be smaller than the number of points. Evaluate several values chosen with domain knowledge, and compare both the score distributions and the set of flagged points across them. Points that remain flagged over the range of k values are more credible than points that appear for only one setting. Keep k below the size of any tight group of outliers, because otherwise that group forms its own dense neighborhood and its members can receive scores close to 1. Small values of k are sensitive to noise, and very large values blur local structure.
What does a LOF score of 1 versus 3 mean?
A score close to 1 means the point's local density is similar to that of its neighbors. A score noticeably above 1 means the point's neighbors lie in denser regions than the point itself, which marks it as a local outlier. There is no universal cutoff. The threshold should be chosen by inspecting the distribution of LOF scores for the specific dataset.
Can LOF score new, unseen points without retraining?
LOF needs the training data to compute neighborhoods and densities. To score a new observation, the stored training points must be available so that its k-neighborhood can be found and its density compared with theirs. This differs from parametric models that keep a compact fitted scoring function. Some implementations provide this capability, but the training data must still be retained.
How does LOF compare to Isolation Forest for anomaly detection?
The two methods measure different things. LOF compares local density across neighborhoods, while Isolation Forest, listed among the related methods, isolates points through random partitioning. They can disagree when anomalies sit in sparse regions of a heterogeneous space, so running both on the same data is more informative than relying on a general ranking. Computational cost and data dimensionality are also practical factors in the choice.
Related methods
Sources
Breunig, M. M., Kriegel, H.-P., Ng, R. T., & Sander, J. (2000). LOF: Identifying density-based local outliers. Proceedings of the 2000 ACM SIGMOD International Conference on Management of Data, 93–104.
Open DOI referenceAggarwal, C. C. (2017). Outlier Analysis (2nd ed., Ch. 4). Springer.
ISBN: 978-3-319-47577-6Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed., Ch. 14). Springer.
ISBN: 978-0-387-84857-02015_Book_DataMining, Section 8.5.2.1 (Local Outlier Factor), p. 253