Class: 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.
Constructors
new IsolationForest()
new IsolationForest(
opts
?):IsolationForest
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.bootstrap ? | boolean | If true , individual trees are fit on random subsets of the training data sampled with replacement. If false , sampling without replacement is performed. |
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. |
opts.max_features ? | number | The number of features to draw from X to train each base estimator. |
opts.max_samples ? | number | "auto" | If int, then draw max_samples samples. |
opts.n_estimators ? | number | The number of base estimators in the ensemble. |
opts.n_jobs ? | number | The number of jobs to run in parallel for both fit and predict . undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details. |
opts.random_state ? | number | Controls 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 ? | number | Controls the verbosity of the tree building process. |
opts.warm_start ? | boolean | When 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. |
Returns IsolationForest
Defined in generated/ensemble/IsolationForest.ts:33
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/ensemble/IsolationForest.ts:31 |
_isInitialized | boolean | false | generated/ensemble/IsolationForest.ts:30 |
_py | PythonBridge | undefined | generated/ensemble/IsolationForest.ts:29 |
id | string | undefined | generated/ensemble/IsolationForest.ts:26 |
opts | any | undefined | generated/ensemble/IsolationForest.ts:27 |
Accessors
estimator_
Get Signature
get estimator_():
Promise
<any
>
The child estimator template used to create the collection of fitted sub-estimators.
Returns Promise
<any
>
Defined in generated/ensemble/IsolationForest.ts:434
estimators_
Get Signature
get estimators_():
Promise
<any
>
The collection of fitted sub-estimators.
Returns Promise
<any
>
Defined in generated/ensemble/IsolationForest.ts:459
estimators_features_
Get Signature
get estimators_features_():
Promise
<any
>
The subset of drawn features for each base estimator.
Returns Promise
<any
>
Defined in generated/ensemble/IsolationForest.ts:484
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/IsolationForest.ts:584
max_samples_
Get Signature
get max_samples_():
Promise
<number
>
The actual number of samples.
Returns Promise
<number
>
Defined in generated/ensemble/IsolationForest.ts:509
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/ensemble/IsolationForest.ts:559
offset_
Get Signature
get offset_():
Promise
<number
>
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.
Returns Promise
<number
>
Defined in generated/ensemble/IsolationForest.ts:534
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/ensemble/IsolationForest.ts:99
Methods
decision_function()
decision_function(
opts
):Promise
<ArrayLike
>
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.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:172
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/ensemble/IsolationForest.ts:151
fit()
fit(
opts
):Promise
<any
>
Fit estimator.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. If undefined , then samples are equally weighted. |
opts.X ? | ArrayLike | The input samples. Use dtype=np.float32 for maximum efficiency. Sparse matrices are also supported, use sparse csc_matrix for maximum efficiency. |
opts.y ? | any | Not used, present for API consistency by convention. |
Returns Promise
<any
>
Defined in generated/ensemble/IsolationForest.ts:206
fit_predict()
fit_predict(
opts
):Promise
<ArrayLike
>
Perform fit on X and returns labels for X.
Returns -1 for outliers and 1 for inliers.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.kwargs ? | any | Arguments to be passed to fit . |
opts.X ? | ArrayLike | The input samples. |
opts.y ? | any | Not used, present for API consistency by convention. |
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/IsolationForest.ts:250
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRouter encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/ensemble/IsolationForest.ts:294
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/ensemble/IsolationForest.ts:112
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict if a particular sample is an outlier or not.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The 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:328
score_samples()
score_samples(
opts
):Promise
<ArrayLike
>
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.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike | The input samples. |
Returns Promise
<ArrayLike
>
Defined in generated/ensemble/IsolationForest.ts:364
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/ensemble/IsolationForest.ts:400