Autoencoder#

class capymoa.anomaly.Autoencoder[source]#

Bases: AnomalyDetector

Autoencoder anomaly detector

This is a simple autoencoder anomaly detector that uses a single hidden layer.

Reference:

Contextual One-Class Classification in Data Streams. Richard Hugh Moulton, Herna L. Viktor, Nathalie Japkowicz, and João Gama. arXiv:1907.04233, 2019.

Example:

>>> from capymoa.datasets import ElectricityTiny
>>> from capymoa.anomaly import Autoencoder
>>> from capymoa.evaluation import AnomalyDetectionEvaluator
>>> stream = ElectricityTiny()
>>> schema = stream.get_schema()
>>> learner = Autoencoder(schema=schema)
>>> evaluator = AnomalyDetectionEvaluator(schema)
>>> while stream.has_more_instances():
...     instance = stream.next_instance()
...     proba = learner.score_instance(instance)
...     evaluator.update(instance.y_index, proba)
...     learner.train(instance)
>>> auc = evaluator.auc()
>>> print(f"AUC: {auc:.2f}")
AUC: 0.42
__init__(
schema=None,
hidden_layer=2,
learning_rate=0.5,
threshold=0.6,
random_seed=1,
)[source]#

Construct an Autoencoder anomaly detector

Parameters :param schema: The schema of the input data :param hidden_layer: Number of neurons in the hidden layer. The number should less than the number of input features. :param learning_rate: Learning rate :param threshold: Anomaly threshold :param random_seed: Random seed

train(instance: Instance)[source]#
predict(instance: Instance) int[source]#
score_instance(instance: Instance) float64[source]#