Skip to content

Clustering, density estimation, and anomaly detection · Anomaly detection · UCL051 · Algorithm

Local Outlier Probabilities (LoOP)

Transform local distance deviations into bounded, probability-like outlier scores. It aims to make local scores easier to compare than raw density ratios while retaining neighborhood adaptation.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.lof. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Transform local distance deviations into bounded, probability-like outlier scores. It aims to make local scores easier to compare than raw density ratios while retaining neighborhood adaptation.

Question / hypotheses

Which observations deviate from the chosen reference notion of normality, and at what operational alert rate? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

Neighborhood distance scales, normalized relative deviations, and an error-function mapping.

Assumptions

The distributional approximation behind the mapping is not a guarantee of calibrated real-world probability. Local neighborhoods must be meaningful and sufficiently populated; duplicates need numerical safeguards.

Formula / computational definition

Let σ(x)=∣N(x)∣−1∑y∈N(x)d(x,y)2\sigma(x)=\sqrt{|N(x)|^{-1}\sum_{y\in N(x)}d(x,y)^2} and pdist(x)=λσ(x)pdist(x)=\lambda\sigma(x). Define PLOF(x)=pdist(x)/mean⁡y∈N(x)pdist(y)−1PLOF(x)=pdist(x)/\operatorname{mean}_{y\in N(x)}pdist(y)-1. A normalized PLOF scale maps this deviation through an error function, with negative scores clipped to zero.

Parameters and notation

Learned or fitted quantities: Neighborhood statistics and a selected alert threshold; not a learned class posterior. User-set hyperparameters/design choices: Neighbor count, metric, significance multiplier λ\lambda, and scale normalization determine behavior. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Neural fine-tuning is not applicable to this classical detector. Refit the reference model when its population changes, then recalibrate an alert threshold on a separate normal holdout. Tune sensitivity without using final-test anomaly labels repeatedly.

How to use and calibrate

Compare ranking, score stability, and empirical calibration against labeled validation cases if probability interpretation matters. A nominal 0.95 score must not be advertised as a validated 95% anomaly probability without that check.

Example application

Provide bounded local outlier scores for analyst review. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.

Interpretation / pitfalls

Watch out

The reported result is conditional on the representation and objective. An alert is a screening result, not a diagnosis or a calibrated posterior probability. Evaluate both ranking and the decision threshold.

Python and R code examples

Implement the published neighborhood statistics in NumPy; R DDoutlier::LOOP documents a native route. The paired code illustrates the final normalized mapping given PLOF and scale, leaving neighborhood construction to the full algorithm.

Component: LoOP normalized error-function mapping. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — LoOP normalized error-function mapping. · needs numpy, scipy

import numpy as np
from scipy.special import erf
plof=np.array([-.2,.1,1.]); nplof=.6
result=np.maximum(0,erf(plof/(nplof*np.sqrt(2))))
print(result)
R

Component demo, not a trained model — LoOP normalized error-function mapping.

plof=c(-.2,.1,1); nplof=.6
result=pmax(0,2*pnorm(plof/nplof)-1)
print(result)

Sources

From the CodeSplash reference, entry UCL051.