Documentation
Classes
IsolationForest

IsolationForest

Isolation Forest Algorithm.

Return the anomaly score of each sample using the IsolationForest algorithm

The IsolationForest ‘isolates’ observations by randomly selecting a feature and then randomly selecting a split value between the maximum and minimum values of the selected feature.

Since recursive partitioning can be represented by a tree structure, the number of splittings required to isolate a sample is equivalent to the path length from the root node to the terminating node.

This path length, averaged over a forest of such random trees, is a measure of normality and our decision function.

Random partitioning produces noticeably shorter paths for anomalies. Hence, when a forest of random trees collectively produce shorter path lengths for particular samples, they are highly likely to be anomalies.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new IsolationForest(opts?: object): IsolationForest;

Parameters

NameTypeDescription
opts?object-
opts.bootstrap?booleanIf true, individual trees are fit on random subsets of the training data sampled with replacement. If false, sampling without replacement is performed. Default Value false
opts.contamination?number | "auto"The amount of contamination of the data set, i.e. the proportion of outliers in the data set. Used when fitting to define the threshold on the scores of the samples. Default Value 'auto'
opts.max_features?numberThe number of features to draw from X to train each base estimator. Default Value 1
opts.max_samples?number | "auto"If int, then draw max\_samples samples. Default Value 'auto'
opts.n_estimators?numberThe number of base estimators in the ensemble. Default Value 100
opts.n_jobs?numberThe number of jobs to run in parallel for both fit and predict. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details.
opts.random_state?numberControls the pseudo-randomness of the selection of the feature and split values for each branching step and each tree in the forest. Pass an int for reproducible results across multiple function calls. See Glossary.
opts.verbose?numberControls the verbosity of the tree building process. Default Value 0
opts.warm_start?booleanWhen set to true, reuse the solution of the previous call to fit and add more estimators to the ensemble, otherwise, just fit a whole new forest. See the Glossary. Default Value false

Returns

IsolationForest

Defined in: generated/ensemble/IsolationForest.ts:33 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/ensemble/IsolationForest.ts:31 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/ensemble/IsolationForest.ts:30 (opens in a new tab)

_py

PythonBridge

Defined in: generated/ensemble/IsolationForest.ts:29 (opens in a new tab)

id

string

Defined in: generated/ensemble/IsolationForest.ts:26 (opens in a new tab)

opts

any

Defined in: generated/ensemble/IsolationForest.ts:27 (opens in a new tab)

Accessors

estimator_

The child estimator template used to create the collection of fitted sub-estimators.

Signature

estimator_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/IsolationForest.ts:375 (opens in a new tab)

estimators_

The collection of fitted sub-estimators.

Signature

estimators_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/IsolationForest.ts:400 (opens in a new tab)

estimators_features_

The subset of drawn features for each base estimator.

Signature

estimators_features_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/IsolationForest.ts:425 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/IsolationForest.ts:525 (opens in a new tab)

max_samples_

The actual number of samples.

Signature

max_samples_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/IsolationForest.ts:450 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/IsolationForest.ts:500 (opens in a new tab)

offset_

Offset used to define the decision function from the raw scores. We have the relation: decision\_function \= score\_samples \- offset\_. offset\_ is defined as follows. When the contamination parameter is set to “auto”, the offset is equal to -0.5 as the scores of inliers are close to 0 and the scores of outliers are close to -1. When a contamination parameter different than “auto” is provided, the offset is defined in such a way we obtain the expected number of outliers (samples with decision function < 0) in training.

Signature

offset_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/IsolationForest.ts:475 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/ensemble/IsolationForest.ts:99 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/ensemble/IsolationForest.ts:103 (opens in a new tab)

Methods

decision_function()

Average anomaly score of X of the base classifiers.

The anomaly score of an input sample is computed as the mean anomaly score of the trees in the forest.

The measure of normality of an observation given a tree is the depth of the leaf containing this observation, which is equivalent to the number of splittings required to isolate this point. In case of several observations n_left in the leaf, the average path length of a n_left samples isolation tree is added.

Signature

decision_function(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/IsolationForest.ts:183 (opens in a new tab)

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/ensemble/IsolationForest.ts:162 (opens in a new tab)

fit()

Fit estimator.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Use dtype=np.float32 for maximum efficiency. Sparse matrices are also supported, use sparse csc\_matrix for maximum efficiency.
opts.sample_weight?ArrayLikeSample weights. If undefined, then samples are equally weighted.
opts.y?anyNot used, present for API consistency by convention.

Returns

Promise<any>

Defined in: generated/ensemble/IsolationForest.ts:218 (opens in a new tab)

fit_predict()

Perform fit on X and returns labels for X.

Returns -1 for outliers and 1 for inliers.

Signature

fit_predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples.
opts.y?anyNot used, present for API consistency by convention.

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/IsolationForest.ts:267 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/ensemble/IsolationForest.ts:112 (opens in a new tab)

predict()

Predict if a particular sample is an outlier or not.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, it will be converted to dtype=np.float32 and if a sparse matrix is provided to a sparse csr\_matrix.

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/IsolationForest.ts:305 (opens in a new tab)

score_samples()

Opposite of the anomaly score defined in the original paper.

The anomaly score of an input sample is computed as the mean anomaly score of the trees in the forest.

The measure of normality of an observation given a tree is the depth of the leaf containing this observation, which is equivalent to the number of splittings required to isolate this point. In case of several observations n_left in the leaf, the average path length of a n_left samples isolation tree is added.

Signature

score_samples(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples.

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/IsolationForest.ts:342 (opens in a new tab)