Local Outlier Factor#

Local Outlier Factor (LOF) measures the local deviation of density of an unknown sample with respect to its k nearest neighbors from the training set. As such, LOF only considers the local region (or neighborhood) of an unknown sample which enables it to detect anomalies within individual clusters of data.

Interfaces: Estimator, Learner, Ranking, Persistable

Data Type Compatibility: Depends on distance kernel


# Param Default Type Description
1 k 20 int The k nearest neighbors that form a local region.
2 contamination null float The proportion of outliers that are assumed to be present in the training set.
3 tree KDTree Spatial The spatial tree used to run nearest neighbor searches.


use Rubix\ML\AnomalyDetectors\LocalOutlierFactor;
use Rubix\ML\Graph\Trees\BallTree;
use Rubix\ML\Kernels\Distance\Euclidean;

$estimator = new LocalOutlierFactor(20, 0.1, new BallTree(30, new Euclidean));

Additional Methods#

Return the base spatial tree instance:

public tree() : Spatial


  • M. M. Breunig et al. (2000). LOF: Identifying Density-Based Local Outliers.