Skip to content

AnomalySine

Simulate a stream with anomalies in sine waves.

The amount of data generated by this generator is finite.

The data generated corresponds to sine and cosine functions. Anomalies are induced by replacing the cosine values with values from a different a sine function. The contextual flag can be used to introduce contextual anomalies which are values in the normal global range, but abnormal compared to the seasonal pattern. Contextual attributes are introduced by replacing cosine entries with sine values.

The target indicates whether or not the instances are anomalous.

Parameters

  • n_samples

    Typeint

    Default10000

    The number of samples to generate. This generator creates a batch of data affected by contextual anomalies and noise.

  • n_anomalies

    Typeint

    Default2500

    Number of anomalies. Can't be larger than n_samples.

  • contextual

    Typebool

    DefaultFalse

    If True, will add contextual anomalies.

  • n_contextual

    Typeint

    Default2500

    Number of contextual anomalies. Can't be larger than n_samples.

  • shift

    Typeint

    Default4

    Shift in number of samples applied when retrieving contextual anomalies.

  • noise

    Typefloat

    Default0.5

    Amount of noise.

  • replace

    Typebool

    DefaultTrue

    If True, anomalies are randomly sampled with replacement.

  • seed

    Typeint | None

    DefaultNone

    Random seed for reproducibility.

Attributes

  • desc

    Return the description from the docstring.

Examples

from river.datasets import synth

dataset = synth.AnomalySine(
    seed=12345,
    n_samples=100,
    n_anomalies=25,
    contextual=True,
    n_contextual=10
)

for x, y in dataset.take(5):
    print(x, y)
{'sine': -0.7119, 'cosine': 0.8777} False
{'sine': 0.8792, 'cosine': -0.0290} False
{'sine': 0.0440, 'cosine': 3.0852} True
{'sine': 0.5520, 'cosine': 3.4515} True
{'sine': 0.8037, 'cosine': 0.4027} False

Methods

take

Iterate over the k samples.

Parameters

  • k'int'