Local Outlier Factor (LOF)
Local Outlier Factor (LOF): Density-Based Anomaly Detection · Also known as: LOF, local outlier factor, density-based outlier detection, local density deviation
Local Outlier Factor (LOF) is a density-based, unsupervised anomaly detection algorithm introduced by Breunig, Kriegel, Ng, and Sander in 2000. It assigns each data point a continuous outlier score that quantifies how isolated that point is relative to its local neighborhood, enabling detection of anomalies that global methods miss because they blend into dense clusters elsewhere in the space.
Read the full method
Sign in with a free account to read this section.
Method map
The neighbourhood of related methods — select a node to explore.
When to use it
LOF is appropriate when anomalies are expected to occur in clusters of varying density and when a global distance threshold would either miss outliers hidden in sparse regions or incorrectly flag points in legitimately sparse but consistent clusters. It works on any continuous feature space with a meaningful distance metric and does not require labeled anomaly examples (fully unsupervised). It suits applications such as fraud detection, network intrusion detection, manufacturing quality control, and medical anomaly screening. The main assumptions are that inliers form reasonably cohesive local neighborhoods and that meaningful pairwise distances can be computed. LOF performs best when n is at least in the tens to low hundreds; for very high-dimensional data (the curse of dimensionality) distances become less discriminative and dimensionality reduction or feature selection is advisable first.
Strengths & limitations
- Detects local outliers in datasets with clusters of varying density, where global methods fail.
- Produces a continuous, interpretable score rather than a hard binary label, allowing flexible threshold choice.
- Fully unsupervised: no labeled anomaly data are required.
- Applicable to any feature space with a computable distance metric, including non-Euclidean distances.
- Robust to the scale of individual features when distances are computed on standardized data.
- Quadratic time complexity in the naive implementation makes it slow on large datasets without approximate nearest-neighbor indexing.
- Sensitive to the choice of k: too small a k yields noisy scores; too large a k blurs local structure.
- Performance degrades in very high-dimensional spaces due to the curse of dimensionality.
- Does not scale naturally to streaming or online data without recomputation.
- Provides no model that can be directly applied to score new points without access to the training set.
Frequently asked
How do I choose the right value of k?
There is no universally optimal k. Common practice is to evaluate a range of values — typically 5 to 50 — and inspect how the score distribution and flagged outliers change. A sensitivity analysis across k values gives confidence that detected anomalies are robust to the choice. Domain knowledge about the minimum expected cluster size can also guide the lower bound.
What does a LOF score of 1 versus 3 mean?
A score close to 1 means the point has roughly the same local density as its neighbors and is considered an inlier. A score significantly greater than 1 — often interpreted as above 1.5 or 2 depending on the dataset — indicates that the point's neighborhood is much sparser than its neighbors' neighborhoods. 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 is a transductive method: it requires the training set to be present to compute neighborhoods and densities for any new point. To score new observations, the training set must be retained and each new point must be inserted to recompute its k-neighborhood against stored training points. Some implementations offer this functionality, but it differs fundamentally from parametric models that learn a compact scoring function.
How does LOF compare to Isolation Forest for anomaly detection?
LOF uses density estimation based on local neighborhoods and is stronger when anomalies cluster in locally sparse regions of a heterogeneous space. Isolation Forest uses random partitioning and tends to be faster and more scalable to large datasets. For high-dimensional or very large datasets, Isolation Forest is often preferred; for moderate-dimensional data with density variation, LOF frequently offers finer discrimination.
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. DOI: 10.1145/335191.335388 ↗
- Aggarwal, C. C. (2017). Outlier Analysis (2nd ed., Ch. 4). Springer. ISBN: 978-3-319-47577-6
- Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed., Ch. 14). Springer. ISBN: 978-0-387-84857-0
How to cite this page
ScholarGate. (2026, June 3). Local Outlier Factor (LOF): Density-Based Anomaly Detection. ScholarGate. https://scholargate.app/en/machine-learning/local-outlier-factor
Which method?
Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.
- AutoencoderDeep learning↔ compare
- DBSCANMachine learning↔ compare
- Isolation ForestMachine learning↔ compare
- One-class SVMMachine learning↔ compare