@kanaries/ml

IsolationForest

API reference for IsolationForest

Ensemble.IsolationForest

constructor(subsampling_size: number = 256, tree_num: number = 100, contamination: 'auto' | number = 'auto')

Parameters

nametypedefaultdescription
subsampling_sizenumber256Number of samples used to build each tree
tree_numnumber100Number of isolation trees in the forest
contamination'auto' | number'auto'Expected proportion of outliers

Algorithm

IsolationForest randomly splits features to isolate samples. Points that can be isolated with fewer splits are considered anomalies.

Methods

  • fit(samplesX: number[][]): void
  • predict(samplesX: number[][]): (0|1)[]

Example

const iForest = new IsolationForest(256, 10, 0.25);
const X = [[-2, -1], [-1, -1], [-1, -2], [1, 1]];
iForest.fit(X);
const result = iForest.predict(X);