Skip to content

Instantly share code, notes, and snippets.

@preetesh33
Created June 5, 2024 13:57
Show Gist options
  • Save preetesh33/5a1331bf26b510f14971841c7db59458 to your computer and use it in GitHub Desktop.
Save preetesh33/5a1331bf26b510f14971841c7db59458 to your computer and use it in GitHub Desktop.
To add seasonality to your forecasting model, you can use Fourier terms. Fourier terms can capture seasonality of any period and are especially useful when the period of the seasonality is large.
In the `MLForecast` class, you can add Fourier terms using the `seasonality` parameter in the `fit` method. The `seasonality` parameter is a dictionary where the keys are the periods of the seasonality and the values are the order of the Fourier series.
Here's how you can modify your code to add weekly and yearly seasonality:
```python
# Assuming your data is in minutes and you want to capture weekly and yearly seasonality
weekly_seasonality = 60 * 24 * 7 # minutes in a week
yearly_seasonality = 60 * 24 * 365 # minutes in a non-leap year
fcst.fit(
train,
id_col='id_col',
time_col='timestamp',
target_col='totalcalls',
static_features=['location','customer','cluster','project'],
seasonality={weekly_seasonality: 10, yearly_seasonality: 10} # Add Fourier terms for weekly and yearly seasonality
)
```
This will add 10 Fourier terms for each of the weekly and yearly seasonalities. You can adjust the number of Fourier terms based on your specific use case. More Fourier terms can capture more complex seasonal patterns, but can also lead to overfitting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment