Categories &

Functions List

Class Definition: IsolationForest

statistics: IsolationForest

Isolation Forest model for anomaly detection.

An IsolationForest object stores an ensemble of isolation trees fitted to a set of observations and detects anomalies through the isanomaly method. Create an IsolationForest object with iforest or the class constructor.

Anomalies are easier to isolate, so they sit closer to the root of a random isolation tree; the shorter its average path length across the ensemble, the higher an observation’s anomaly score.

See also: iforest, IsolationForest.isanomaly

Source Code: IsolationForest

The IsolationForest class contains the following properties:

The IsolationForest class offers the following public methods:

IsolationForest: Mdl = IsolationForest (X)

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

Mdl = IsolationForest (X) fits an isolation forest to the N-by-P matrix X, whose rows are observations and columns are variables, and returns a IsolationForest object Mdl. X must have at least 3 observations, the smallest subsample MATLAB accepts too; MATLAB takes fewer by default and returns a model that cannot tell one observation from another.

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

NameValue
'NumLearners'the number of isolation trees, a positive integer (default 100).
'NumObservationsPerLearner'the subsample size used to grow each tree, an integer in [3, N] (default min (N, 256)).
'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.

Because the trees are grown from random subsamples and random splits, the model depends on the state of the random number generator and is not reproducible across runs unless the generator is seeded.

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

See also: iforest, IsolationForest.isanomaly

IsolationForest: tf = isanomaly (Mdl, Xnew)

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

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