pysad.models.IForestASD

class pysad.models.IForestASD(initial_window_X=None, window_size=2048)[source]

An Anomaly Detection Approach Based on Isolation Forest Algorithm for Streaming Data using Sliding Window [BDF13]. Note that concept drift is not implemented since it is a part of the simulation. See Algorithm 2 in “An Anomaly Detection Approach Based on Isolation Forest Algorithm for Streaming Data using Sliding Window” paper. This method is unsupervised so it is not needed to give y as parameter.

Parameters
  • initial_window_X (np.float array of shape (num_initial_instances,num_features)) – The initial window to fit for initial calibration period. We simply apply fit to these instances (Default=None).

  • window_size (int) – The size of the reference window and its sliding (Default=2048).

Methods

__init__([initial_window_X, window_size])

Args: model_cls: window_size: sliding_size: initial_window_X: initial_window_y:

fit(X[, y])

Fits the model to all instances in order.

fit_partial(X[, y])

Fits the model to next instance.

fit_score(X[, y])

This helper method applies fit_score_partial to all instances in order.

fit_score_partial(X[, y])

Applies fit_partial and score_partial to the next instance, respectively.

reset_model()

Removes the old model from the memory and instantiates a new one.

score(X)

Scores all instaces via score_partial iteratively.

score_partial(X)

Scores the anomalousness of the next instance.

fit(X, y=None)

Fits the model to all instances in order.

Parameters
  • X (np.float array of shape (num_instances, num_features)) – The instances in order to fit.

  • y (int) – The labels of the instances in order to fit (Optional for unsupervised models, default=None).

Returns

Fitted model.

Return type

object

fit_partial(X, y=None)

Fits the model to next instance.

Parameters
  • X (np.float array of shape (num_features,)) – The instance to fit.

  • y (int) – The label of the instance (Optional for unsupervised models, default=None).

Returns

self.

Return type

object

fit_score(X, y=None)

This helper method applies fit_score_partial to all instances in order.

Parameters
  • X (np.float array of shape (num_instances, num_features)) – The instances in order to fit.

  • y (np.int array of shape (num_instances, )) – The labels of the instances in order to fit (Optional for unsupervised models, default=None).

Returns

The anomalousness scores of the instances in order.

Return type

np.float array of shape (num_instances,)

fit_score_partial(X, y=None)

Applies fit_partial and score_partial to the next instance, respectively.

Parameters
  • X (np.float array of shape (num_features,)) – The instance to fit and score.

  • y (int) – The label of the instance (Optional for unsupervised models, default=None).

Returns

The anomalousness score of the input instance.

Return type

float

reset_model()

Removes the old model from the memory and instantiates a new one.

score(X)

Scores all instaces via score_partial iteratively.

Parameters

X (np.float array of shape (num_instances, num_features)) – The instances in order to score.

Returns

The anomalousness scores of the instances in order.

Return type

np.float array of shape (num_instances,)

score_partial(X)

Scores the anomalousness of the next instance.

Parameters

X (np.float array of shape (num_features,)) – The instance to score. Higher scores represent more anomalous instances whereas lower scores correspond to more normal instances.

Returns

The anomalousness score of the input instance.

Return type

float