Guide to using holiday calendar variables and special dates to improve forecast accuracy in time series.
month | chocolate | |
---|---|---|
0 | 2004-01-31 | 35 |
1 | 2004-02-29 | 45 |
2 | 2004-03-31 | 28 |
3 | 2004-04-30 | 30 |
4 | 2004-05-31 | 29 |
month | |
---|---|
9 | 2025-02-28 00:00:00 |
10 | 2025-03-31 00:00:00 |
11 | 2025-04-30 00:00:00 |
12 | 2025-05-31 00:00:00 |
13 | 2025-06-30 00:00:00 |
add_date_features_to_DataFrame
function that takes:
CountryHolidays
or SpecialDates
CountryHolidays
class to compute US holidays and merge them into the future DataFrame.
month | US_New Year’s Day | US_Memorial Day | US_Juneteenth National Independence Day | US_Independence Day | US_Labor Day | US_Veterans Day | US_Thanksgiving Day | US_Christmas Day | US_Martin Luther King Jr. Day | US_Washington’s Birthday | US_Columbus Day | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2024-05-31 00:00:00 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 2024-06-30 00:00:00 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
2 | 2024-07-31 00:00:00 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
3 | 2024-08-31 00:00:00 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
4 | 2024-09-30 00:00:00 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
month | chocolate | US_New Year’s Day | US_New Year’s Day (observed) | US_Memorial Day | US_Independence Day | US_Independence Day (observed) | US_Labor Day | US_Veterans Day | US_Thanksgiving Day | US_Christmas Day | US_Christmas Day (observed) | US_Martin Luther King Jr. Day | US_Washington’s Birthday | US_Columbus Day | US_Veterans Day (observed) | US_Juneteenth National Independence Day | US_Juneteenth National Independence Day (observed) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
239 | 2023-12-31 00:00:00 | 90 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
240 | 2024-01-31 00:00:00 | 64 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
241 | 2024-02-29 00:00:00 | 66 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
242 | 2024-03-31 00:00:00 | 59 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
243 | 2024-04-30 00:00:00 | 51 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
For more details on how to use the shap library, see our tutorial on model interpretability.
SpecialDates
. These can represent unique one-time events or recurring patterns on specific dates of your choice.
Assume we already have a future DataFrame with monthly dates. We’ll create Valentine’s Day and Halloween as custom special dates and add them to the future DataFrame.
month | Valentine_season | Halloween_season | |
---|---|---|---|
0 | 2024-05-31 00:00:00 | 0 | 0 |
1 | 2024-06-30 00:00:00 | 0 | 0 |
2 | 2024-07-31 00:00:00 | 0 | 0 |
3 | 2024-08-31 00:00:00 | 0 | 0 |
4 | 2024-09-30 00:00:00 | 0 | 0 |
month | chocolate | Valentine_season | Halloween_season | |
---|---|---|---|---|
239 | 2023-12-31 00:00:00 | 90 | 0 | 0 |
240 | 2024-01-31 00:00:00 | 64 | 0 | 0 |
241 | 2024-02-29 00:00:00 | 66 | 1 | 0 |
242 | 2024-03-31 00:00:00 | 59 | 0 | 0 |
243 | 2024-04-30 00:00:00 | 51 | 0 | 0 |