Simulation Data

Orbit provide the functions to generate the simulation data including:

  1. Generate the data with time-series trend:

    • random walk

    • arima

  2. Generate the data with seasonality

    • discrete

    • fourier series

  3. Generate regression data

[1]:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

import orbit
from orbit.utils.simulation import make_trend, make_seasonality, make_regression
from orbit.utils.plot import get_orbit_style
plt.style.use(get_orbit_style())
from orbit.constants.palette import OrbitPalette

%matplotlib inline
[2]:
print(orbit.__version__)
1.1.3dev

Trend

Random Walk

[3]:
rw = make_trend(200, rw_loc=0.02, rw_scale=0.1, seed=2020)
_ = plt.plot(rw, color = OrbitPalette.BLUE.value)
../_images/tutorials_utilities_simulation_5_0.png

ARMA

reference for the ARMA process: https://www.statsmodels.org/stable/generated/statsmodels.tsa.arima_process.ArmaProcess.html

[4]:
arma_trend =  make_trend(200, method='arma', arma=[.8, -.1], seed=2020)
_ = plt.plot(arma_trend, color = OrbitPalette.BLUE.value)
../_images/tutorials_utilities_simulation_7_0.png

Seasonality

Discrete

generating a weekly seasonality(=7) where seasonality within a day is constant(duration=24) on an hourly time-series

[5]:
ds = make_seasonality(500, seasonality=7, duration=24, method='discrete', seed=2020)
_ = plt.plot(ds, color = OrbitPalette.BLUE.value)
../_images/tutorials_utilities_simulation_11_0.png

Fourier

generating a sine-cosine wave seasonality for a annual seasonality(=365) using fourier series

[6]:
fs = make_seasonality(365 * 3, seasonality=365, method='fourier', order=5, seed=2020)
_ = plt.plot(fs, color = OrbitPalette.BLUE.value)
../_images/tutorials_utilities_simulation_14_0.png
[7]:
fs
[7]:
array([0.01162034, 0.00739299, 0.00282248, ..., 0.02173615, 0.01883928,
       0.01545216])

Regression

generating multiplicative time-series with trend, seasonality and regression components

[8]:
# define the regression coefficients
coefs = [0.1, -.33, 0.8]
[9]:
x, y, coefs = make_regression(200, coefs, scale=2.0, seed=2020)
[10]:
_ = plt.plot(y, color = OrbitPalette.BLUE.value)
../_images/tutorials_utilities_simulation_20_0.png
[11]:
# check if get the coefficients as set up
reg = LinearRegression().fit(x, y)
print(reg.coef_)
[ 0.1586677  -0.33126796  0.7974205 ]