Skip to main content

LocalOutlierFactor

A density-based anomaly score: each point is compared to the local density of its neighbours, flagging those in relatively sparse regions as outliers.

Algorithm​

Computes the local reachability density of each point and the ratio to its neighbours' densities (the local outlier factor). Scores far below 1 indicate inliers; large scores indicate outliers. Exposed as the negated factor to match scikit-learn's convention.

Constructor​

Skigen::LocalOutlierFactor<Scalar> model(int n_neighbors = 20, Scalar contamination = -1);

Parameters​

ParameterDefaultDescription
n_neighbors20Neighbours used for the density estimate.
contamination-1Expected outlier fraction; -1 disables automatic thresholding.

Methods​

MethodDescription
fit(X)Score every training point.
fit_predict_labels(X)Inlier/outlier labels.

Fitted Attributes​

AccessorDescription
negative_outlier_factor()Negated LOF scores (lower = more anomalous).
n_neighbors_used()Effective neighbour count.

Example​

Skigen::LocalOutlierFactor<double> lof(20);
lof.fit(X);
auto scores = lof.negative_outlier_factor();
Verified against scikit-learn

This estimator is checked by the parity suite. See the generator tests/parity/generate_neighbors_reference.py and the reference fixtures in tests/parity/data/local_outlier_factor/, exercised by tests/parity/parity_neighbors.cpp.

API Reference

For full signatures see the LocalOutlierFactor API Reference.