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
Type →
intDefault →
10000The number of samples to generate. This generator creates a batch of data affected by contextual anomalies and noise.
-
n_anomalies
Type →
intDefault →
2500Number of anomalies. Can't be larger than
n_samples. -
contextual
Type →
boolDefault →
FalseIf True, will add contextual anomalies.
-
n_contextual
Type →
intDefault →
2500Number of contextual anomalies. Can't be larger than
n_samples. -
shift
Type →
intDefault →
4Shift in number of samples applied when retrieving contextual anomalies.
-
noise
Type →
floatDefault →
0.5Amount of noise.
-
replace
Type →
boolDefault →
TrueIf True, anomalies are randomly sampled with replacement.
-
seed
Type →
int | NoneDefault →
NoneRandom 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