Fourier Components

Generate fourier components for fourier seasonality

source

generate_fourier_components

 generate_fourier_components (N_samples:int, N_components:int=3,
                              period:int=52)

Generate Fourier components for a given number of samples and components.

Type Default Details
N_samples int Number of samples
N_components int 3 Half the number of Fourier components
period int 52 Yearly period of weekly data
Returns DataFrame Dataframe with fourier components
period = pd.date_range("2021-01-01", periods=156, freq="W-MON")
fourier_components = generate_fourier_components(period.shape[0], 3, 52)
fourier_components.head()
fourier_sin_0 fourier_sin_1 fourier_sin_2 fourier_cos_0 fourier_cos_1 fourier_cos_2
0 0.000000 0.000000 0.000000 1.000000 1.000000 1.000000
1 0.121311 0.240829 0.356791 0.992615 0.970568 0.934184
2 0.240829 0.467482 0.666616 0.970568 0.884003 0.745401
3 0.356791 0.666616 0.888695 0.934184 0.745401 0.458499
4 0.467482 0.826511 0.993793 0.884003 0.562921 0.111245
Figure 1: Fourier components.
Figure 2: Samples of linear combination of fourier components.