Generate seasons in time series¶
In [1]:
Copied!
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from badgers.generators.time_series.seasons import GlobalAdditiveSinusoidalSeasonGenerator
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from badgers.generators.time_series.seasons import GlobalAdditiveSinusoidalSeasonGenerator
Setup random generator¶
In [2]:
Copied!
from numpy.random import default_rng
seed = 0
rng = default_rng(seed)
from numpy.random import default_rng
seed = 0
rng = default_rng(seed)
Generate data (gaussian white noise)¶
In [3]:
Copied!
X = pd.DataFrame(data=rng.normal(loc=0, scale=0.1, size=(100, 2)), columns=['dimension_0', 'dimension_1'])
X = pd.DataFrame(data=rng.normal(loc=0, scale=0.1, size=(100, 2)), columns=['dimension_0', 'dimension_1'])
In [4]:
Copied!
X.plot(subplots=True)
X.plot(subplots=True)
Out[4]:
array([<Axes: >, <Axes: >], dtype=object)
Add sinusoidal season¶
In [5]:
Copied!
generator = GlobalAdditiveSinusoidalSeasonGenerator(random_generator=rng)
generator = GlobalAdditiveSinusoidalSeasonGenerator(random_generator=rng)
In [6]:
Copied!
Xt, _ = generator.generate(X=X, y=None, period=np.array([10,50]))
Xt, _ = generator.generate(X=X, y=None, period=np.array([10,50]))
In [7]:
Copied!
fig, axes = plt.subplots(2, sharex=True, sharey=True, figsize=(6,6))
X.plot(ax=axes[0])
axes[0].set_title('Original data')
Xt.plot(ax=axes[1])
axes[1].set_title('Transformed data')
plt.tight_layout();
fig, axes = plt.subplots(2, sharex=True, sharey=True, figsize=(6,6))
X.plot(ax=axes[0])
axes[0].set_title('Original data')
Xt.plot(ax=axes[1])
axes[1].set_title('Transformed data')
plt.tight_layout();
In [ ]:
Copied!