Class IsolationForest
- All Implemented Interfaces:
Serializable
Rather than selecting a random feature and value within the range of data, Extended isolation forest slices the data using hyperplanes with random slopes. The consistency and reliability of the algorithm is much improved using this extension.
For an N dimensional dataset, we can consider N levels of extension.
In the fully extended case, we select our normal vector by drawing
each component from N (0, 1) as seen before. This results
in hyperplanes that can intersect any of the coordinates axes.
However, we can exclude some dimensions in specifying the lines
so that they are parallel to the coordinate axes. This is simply
accomplished by setting a coordinate of the normal vector to zero.
The lowest level of extension of the Extended Isolation Forest
is coincident with the standard Isolation Forest. As the extension
level of the algorithm is increased, the bias of the algorithm is
reduced. The idea of having multiple levels of extension can be useful
in cases where the dynamic range of the data in various dimensions are
very different. In such cases, reducing the extension level can help in
more appropriate selection of split hyperplanes.
References
- Fei Liu, Kai Ming Ting, and Zhi-Hua Zhou. Isolation Forest. ICDM, 413–422, 2008.
- Sahand Hariri, Matias Carrasco Kind, and Robert J. Brunner. Extended Isolation Forest. IEEE Transactions on Knowledge and Data Engineering, 2019.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordIsolation Forest hyperparameters. -
Constructor Summary
ConstructorsConstructorDescriptionIsolationForest(int n, int p, int extensionLevel, IsolationTree... trees) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the extension level.static IsolationForestfit(double[][] data) Fits an isolation forest.static IsolationForestfit(double[][] data, IsolationForest.Options options) Fits an isolation forest.booleanpredict(double[] x, double threshold) Predicts whether a sample is an anomaly using the given threshold.doublescore(double[] x) Returns the anomaly score in the range(0, 1].double[]score(double[][] x) Returns the anomaly scores.intsize()Returns the number of trees in the model.trees()Returns the isolation trees in the model.
-
Constructor Details
-
IsolationForest
Constructor.- Parameters:
n- the number of samples to train the forest.p- the dimensionality of input samples.extensionLevel- the extension level, i.e. how many dimension are specified in the random slope.0means standard Isolation Forest.trees- forest of isolation trees.
-
-
Method Details
-
fit
Fits an isolation forest.- Parameters:
data- the training data. When using default options, this fits standard Isolation Forest (extensionLevel = 0).- Returns:
- the model.
-
fit
Fits an isolation forest.- Parameters:
data- the training data.options- the hyperparameters. In particular,options.extensionLevel()controls extension level.0means standard Isolation Forest.- Returns:
- the model.
-
size
public int size()Returns the number of trees in the model.- Returns:
- the number of trees in the model.
-
trees
Returns the isolation trees in the model.- Returns:
- the isolation trees in the model.
-
extensionLevel
public int extensionLevel()Returns the extension level.0means standard Isolation Forest. Valid range is[0, p-1], wherepis input dimensionality.- Returns:
- the extension level.
-
score
public double score(double[] x) Returns the anomaly score in the range(0, 1]. Scores closer to 1 indicate anomalies; scores around 0.5 are normal. Specifically, a score significantly above 0.5 (e.g.,> 0.6) suggests an anomaly, while a score well below 0.5 suggests a normal instance.- Parameters:
x- the sample.- Returns:
- the anomaly score in
(0, 1].
-
score
public double[] score(double[][] x) Returns the anomaly scores.- Parameters:
x- the samples.- Returns:
- the anomaly scores in
(0, 1].
-
predict
public boolean predict(double[] x, double threshold) Predicts whether a sample is an anomaly using the given threshold.- Parameters:
x- the sample.threshold- the anomaly score threshold. A sample is considered an anomaly if its score exceeds this value. Typical values are in the range(0.5, 1.0).- Returns:
trueif the sample is predicted as an anomaly.
-