AI Glossary / Data science and analytics / Intermediate

Local outlier factor

Definition

Local outlier factor, or LOF, is a method that scores how unusual an observation is relative to the density around its neighbors. It compares a point's local reachability density with those of nearby points. A point in a substantially sparser neighborhood than its neighbors can receive a high LOF score. The score indicates a form of local unusualness, not the probability that the observation is erroneous or harmful.

What it means

A dataset can contain both dense and sparse regions that are entirely legitimate. A single global distance rule may treat ordinary members of the sparse region as anomalies. LOF instead asks whether a point's local surroundings are sparse compared with the surroundings of nearby points. This local comparison can reveal observations that do not stand out under a global rule, but its result still depends on the features, distance measure, and neighborhood size.

How it works

Choose a distance measure and a neighborhood parameter k. For each point, identify nearby points and their kth-neighbor distances. The reachability distance from point p to neighbor o is the larger of their ordinary distance and o's kth-neighbor distance. Local reachability density is the reciprocal of the average reachability distance to neighbors. LOF is the average of the neighbors' local densities divided by p's local density. Scores around one indicate comparable local densities; larger scores indicate lower density relative to neighbors. Implementations may expose a sign-reversed score, so check the documented convention.

Three practical examples

  • Sensor review: engineers rank observations whose combinations of measurements are unusual relative to nearby operating conditions.
  • Data cleaning: analysts investigate records that may contain entry errors without automatically deleting every unusual case.
  • Operational monitoring: a team evaluates whether locally unusual activity patterns help prioritize cases for human investigation.

Think of it this way

Think of comparing how much space surrounds one house with how closely packed its nearby houses are. A house at the edge of a dense group may look unusually isolated even if a different, spacious neighborhood is normal. The analogy concerns relative spacing, not whether a house or an observation is defective.

Worked example

Take four one-dimensional points at 0, 1, 2, and 10, using absolute distance and k = 2, excluding each point itself. The kth-neighbor distances for 0, 1, 2, and 10 are 2, 1, 2, and 9. For point 1, its neighbors are 0 and 2. Both reachability distances are 2, so its local density is 1/2. For point 2, neighbors are 1 and 0, with reachability distances 1 and 2; its density is 1/1.5 = 2/3.
Point 10 has neighbors 2 and 1. Its reachability distances are max(8, 2) = 8 and max(9, 1) = 9. Its density is 1/8.5 = 2/17. The average neighbor density is ((2/3) + (1/2))/2 = 7/12. Dividing by 2/17 gives LOF approximately 4.96. This high score reflects the point's sparse position relative to those neighbors. It does not mean a 496% error probability. The example is a small hand calculation, not a recommended neighborhood size for operational data.

Illustrative case study

In a fictional machine-monitoring project, an analyst flags records with high LOF scores. Engineers find that some represent a rare but legitimate startup mode absent from much of the reference data. The team reviews the intended comparison population and evaluates performance across operating modes before setting an alert policy. It retains rare valid records and documents which cases actually require intervention. The case illustrates why anomaly scores need context and labeled review outcomes rather than being treated as automatic fault diagnoses.

Common misconceptions and mistakes

LOF is not simply distance to the nearest point, and it is not a probability score. An observation can be unusual locally without being globally extreme. A dense group of problematic observations may not look anomalous relative to itself. Changing k changes the scale of comparison. Feature units, irrelevant dimensions, and repeated records can distort neighborhoods. In scikit-learn, ordinary outlier detection on the fitted dataset and novelty detection on new unseen data use different interfaces; training scores and new-data scores should not be interchanged casually.

Business use

Use LOF to support a review process with a clear definition of useful findings. Evaluate the cost of false alerts, the capacity of reviewers, and whether the reference population matches the operational setting. Fit preprocessing consistently and inspect sensitivity to neighborhood choices. Keep the score convention and threshold documented. A contamination setting used to choose a cutoff is not independent evidence of the true anomaly rate. Monitor changes in normal behavior so a previously rare legitimate pattern does not generate a persistent stream of unnecessary alerts.

People also ask

Does LOF require labeled anomalies for its basic calculation?

No, although labeled review results are valuable for evaluating usefulness.

Does a high score prove a fault?

No. It identifies relative local sparsity under the chosen representation.

Why can some software return negative values?

It may expose the negative of the conventional LOF score; in that case more negative can mean more unusual.

Check your understanding

Why is point 10's LOF much larger than one in the example?

Answer: Its local reachability density is 2/17, much lower than the average density 7/12 of its neighbors. The ratio is about 4.96.

Related terms

  • Anomaly detection
  • Nearest neighbor
  • Novelty detection
  • nearest neighbors
  • local density
  • reachability distance
  • distance metric
  • feature scaling
  • contamination

Learn next

Trace reachability distances and local densities for a small dataset before using a library. Then vary k and feature scaling to see how the ranking changes. Study the difference between finding outliers within a dataset and scoring new observations against a reference set.

More in Data science and analytics

  • Lift - Lift is a ratio that compares an observed or model-selected outcome with a stated baseline.
  • Line chart - A line chart displays values as points connected in an ordered sequence, commonly to show change over time.
  • List - A list is an ordered collection of elements. In programming, the exact operations and implementation depend on the language.
  • Logarithm - A logarithm gives the exponent needed to raise a specified base to a positive number. If b raised to y equals x, then log base b of x equals y.
  • Long Short-Term Memory - Long Short-Term Memory, usually abbreviated LSTM, is a type of recurrent neural network designed to learn relationships across sequences.
  • Loops - Loops are programming structures that repeat a block of instructions. A loop may visit each item in a collection or continue while a condition remains true.

Sources

Breunig, Kriegel, Ng, and Sander, original LOF paper: https://sigmodrecord.org/2000/06/07/lof-identifying-density-based-local-outliers/ Scikit-learn, LOF score conventions and parameters: https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.LocalOutlierFactor.html Scikit-learn, outlier versus novelty detection: https://scikit-learn.org/stable/modules/outlier_detection.html#local-outlier-factor

Previous: Local model Next: Local regression

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer