pysad.models.KitNet

class pysad.models.KitNet(max_size_ae=10, grace_feature_mapping=None, grace_anomaly_detector=50000, learning_rate=0.1, hidden_ratio=0.75)[source]

KitNET is a lightweight online anomaly detection algorithm based on an ensemble of autoencoders [BMDES18]. This model directly uses the implementation from KitNET-py.

Parameters
  • num_features (int) – The number of features in your input dataset.

  • max_size_ae (int) – The maximum size of any autoencoder in the ensemble layer (Default=10).

  • grace_feature_mapping (int) – The number of instances the network will learn from before producing anomaly scores (Default=None).

  • grace_anomaly_detector (int) – The number of instances which will be taken to learn the feature mapping. If ‘None’, then FM_grace_period=AM_grace_period. (Default=50000).

  • learning_rate (float) – The default stochastic gradient descent learning rate for all autoencoders in the KitNET instance (Default=0.1).

  • hidden_ratio (float) – The default ratio of hidden to visible neurons. E.g., 0.75 will cause roughly a 25% compression in the hidden layer (Default=0.75).

Methods

__init__([max_size_ae, …])

Initialize self.

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.

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)[source]

Fits the model to next instance. Simply, adds the instance to the window.

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

  • y (int) – Ignored since the model is unsupervised (Default=None).

Returns

Returns the 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

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)[source]

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