Local Outlier Factor (LOF) calculator
Detect local anomalies and outliers in multi-dimensional data using the Local Outlier Factor (LOF) algorithm online.
What it does
You have no confirmed examples of 'unusual' cases and care about points odd relative to their local neighbourhood (not just globally rare), so a density-based method that compares each point's local density to its neighbours' fits better than a single global rule.
When to use it
Each point gets an anomaly score reflecting how much less dense its neighbourhood is than its neighbours' neighbourhoods — high scores mean 'locally unusual', not 'rare in an absolute sense'.
Worked example
You are screening transactions for fraud. A £5,000 payment is not unusual for a corporate account but is very unusual for a student one. LOF compares each point with its own neighbours rather than with the dataset as a whole, so it flags what is odd in context rather than merely large.
Cautions
- The flagged rate is driven by the threshold you chose, not a discovered fact about how much of your data is truly anomalous — different detectors and different neighbourhood sizes will legitimately disagree, and a flagged point is a candidate for human review, not a confirmed error/fraud/event without that follow-up.
- Features are scaled first (this method is distance-based, so an unscaled large-unit feature would dominate), and because 'anomalous' here is defined relative to the chosen neighbourhood size and feature set, the score's stability across neighbourhood size and across resamples/seeds is checked before any point is called an outlier with confidence.
Alternatives
- A global statistical rule (z-score/IQR fences) — Those flag points extreme across the WHOLE dataset; a point that is normal globally but unusual for its local neighbourhood would be missed entirely.
- Supervised classification — You don't have any labelled 'unusual' examples to train a classifier on — with even a few labels, that route would beat an unsupervised score decisively, but without them a local-density score is what's available.
How to read the output
- The LOF score
- Around 1 means the point is as densely surrounded as its neighbours are. Above 1 means it sits in a relatively sparse patch; points above 1.5 are flagged here. The threshold is a convention, not a test. There is no p-value: this is a ranking, and the cut is where you decide to stop reading.
- Neighbours (k)
- How many neighbours define 'locally'. Small k reacts to individual gaps; large k approaches a global notion of outlyingness. k must be smaller than the sample; it is capped automatically. A point that is flagged at one k and not at another has not been shown to be anything — sweep k before trusting a flag.
- Whether the data were scaled
- Every method here works on distances, and a distance adds up your columns' units. Standardizing puts each variable on the same footing before that sum is taken. Unscaled, the variable with the largest numeric range silently becomes the clustering. Income in pounds against age in years is a clustering of income. Turn scaling off only when the raw units are genuinely comparable and you mean to keep their relative weight.
- What a flag means
- That the point is unusual in the variables you selected. Nothing about whether it is wrong. Never delete rows because they were flagged. Go and look at them: an anomaly is a data-entry error, a genuinely unusual subject, or the most interesting case in the file, and only inspection distinguishes those.
How this calculator is validated · Which statistical test should I use?