Skip to content


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.


  • n_samples ('int') – defaults to 10000

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

  • n_anomalies ('int') – defaults to 2500

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

  • contextual ('bool') – defaults to False

    If True, will add contextual anomalies.

  • n_contextual ('int') – defaults to 2500

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

  • shift ('int') – defaults to 4

    Shift in number of samples applied when retrieving contextual anomalies.

  • noise ('float') – defaults to 0.5

    Amount of noise.

  • replace ('bool') – defaults to True

    If True, anomalies are randomly sampled with replacement.

  • seed ('int | None') – defaults to None

    Random seed for reproducibility.


  • desc

    Return the description from the docstring.


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



Iterate over the k samples.


  • k (int)