Categories &

Functions List

Class Definition: LocalOutlierFactor

statistics: LocalOutlierFactor

Local Outlier Factor model for anomaly detection.

A LocalOutlierFactor object stores a Local Outlier Factor (LOF) model fitted to a set of observations, and detects anomalies among those or new observations through the isanomaly method. Create a LocalOutlierFactor object with lof or the class constructor.

The LOF of an observation compares its local density with the local density of its neighbors; a value near 1 indicates an inlier, whereas a value well above 1 indicates an outlier that lies in a sparser region than its neighbors.

See also: lof, LocalOutlierFactor.isanomaly

Source Code: LocalOutlierFactor

The LocalOutlierFactor class contains the following properties:

The LocalOutlierFactor class offers the following public methods:

LocalOutlierFactor: Mdl = LocalOutlierFactor (X)

LocalOutlierFactor: Mdl = LocalOutlierFactor (…, name, value)

Mdl = LocalOutlierFactor (X) fits a Local Outlier Factor model to the N-by-P matrix X, whose rows are observations and columns are variables, and returns a LocalOutlierFactor object Mdl.

Mdl = LocalOutlierFactor (…, name, value) takes the following Name-Value pairs.

NameValue
'NumNeighbors'the number of nearest neighbors, a positive integer less than N. The default is min (20, u - 1), where u is the number of unique observations.
'Distance'the distance metric used to find neighbors, one of the metrics accepted by pdist2 ('euclidean' by default).
'ContaminationFraction'the assumed fraction of anomalies in X, a scalar in [0, 1] (default 0). It sets Mdl.ScoreThreshold to the 1 - ContaminationFraction quantile of the anomaly scores of X; when it is 0 the threshold is the maximum score and no training observation is flagged.
'Exponent'the Minkowski distance exponent (default 2), used only with the 'minkowski' distance.
'Cov'the covariance matrix used only with the 'mahalanobis' distance.

lof fits the same model and also returns the anomaly indicators and the anomaly scores of the observations in X.

See also: lof, LocalOutlierFactor.isanomaly

LocalOutlierFactor: tf = isanomaly (Mdl, Xnew)

LocalOutlierFactor: [tf, scores] = isanomaly (Mdl, Xnew)

LocalOutlierFactor: […] = isanomaly (…, 'ScoreThreshold', t)