[ENH] HolidayFeatures: offset labels and signed distances for holiday window days
Is your feature request related to a problem? Please describe.
With holiday_windows, HolidayFeatures gives every day in a window the same label. For holiday_windows={"Christmas": (2, 1)}, Dec 23 to Dec 26 are all labeled "Christmas", so a model can't tell the day before Christmas from the day after.
In forecasting these days often behave differently: sales usually peak before Christmas and drop on the day itself. The pattern tends to repeat every year at the same distance from the holiday. For movable holidays like Easter or Thanksgiving that distance doesn't map to a fixed calendar date, so right now you have to build these features yourself.
There are two use cases, and they need different encodings:
- One group key per day, e.g. "Christmas-2". I'd like to use this for a holiday-aware naive forecaster that averages past values at the same holiday offset, for example as the residual model in
ResidualBoostingForecaster. I'll propose that separately. - A numeric distance per holiday for tree-based models, so they can split on it (e.g.
Christmas_distance >= -3) instead of seeing each window day as an unrelated dummy.
This builds on the window fixes in #11311.
Describe the solution you'd like
Two new parameters, both False by default, so the current behavior stays unchanged.
return_offsets=True labels each window day with the holiday name and its signed offset, e.g. "Christmas-2", "Christmas+0" for the holiday itself, or "Easter+1", in both the categorical and the dummy output. If windows overlap, a day gets the label of the nearest holiday, and on a tie the upcoming one (negative offset). The default mode combines names instead ("Christmas, New Year"), and the docstring would say so.
return_distances=True adds one float column per key of holiday_windows, named "<name>_distance". The value is the signed number of days from the holiday, with the same sign as the offset labels: -2 two days before, 0 on the holiday, +1 the day after. Outside the window the value is NaN. Tree models such as LightGBM or HistGradientBoostingRegressor handle that natively; for linear models you'd impute. Each holiday has its own column, so overlapping windows don't conflict: Dec 29 can be 4 days after Christmas and 3 days before New Year at the same time. If two occurrences of the same holiday are in reach, the nearest one counts, on a tie the upcoming one. The columns come from the holiday_windows keys, not from the data, so fit and predict see the same columns; a holiday outside the index range gives an all-NaN column. return_distances=True without holiday_windows raises a ValueError. Bridge days and weekends don't affect the distances.
The flags are independent, like the existing return_* flags: the distance columns can come with the categorical, the dummies and the indicator, in either label mode.
Both modes split names that the holidays package joins with "; " and treat each as its own holiday. Names are used as they come, so "(observed)" suffixes stay. The docstring would mention that you can pass observed=False or a fixed language to the holidays calendar, or use a plain dict.
The forecaster would call the same private function that HolidayFeatures uses.
Describe alternatives you've considered
A dict calendar with one entry per offset ({date: "Christmas-2", ...}) works for fixed-date holidays. For movable ones you'd have to compute it per year, and you can't use holidays.HolidayBase anymore.
I also considered combined labels in offset mode, like "Christmas+6, NewYear-1". Those turn into rare categories with little data behind them, so I went with one label per day. The distance columns keep the information that this rule drops on overlapping days.
Parsing the distances out of the offset labels loses exactly that information, which is why they are a separate option.
For the distances, I considered a sentinel value outside the window (e.g. window size + 1), which would keep the columns integer. It's an invented value that differs per holiday, so I prefer NaN. Distances for the whole year instead of only inside the window, and two columns per holiday (days until, days since), are possible follow-ups.
Additional context
Example with calendar={2025-12-25: "Christmas", 2026-01-01: "NewYear"}, holiday_windows={"Christmas": (2, 4), "NewYear": (3, 0)}, return_offsets=True, return_distances=True, return_categorical=True, return_dummies=False:
| date | holiday | Christmas_distance | NewYear_distance |
|---|---|---|---|
| 2025-12-23 | Christmas-2 | -2 | NaN |
| 2025-12-24 | Christmas-1 | -1 | NaN |
| 2025-12-25 | Christmas+0 | 0 | NaN |
| 2025-12-26 | Christmas+1 | 1 | NaN |
| 2025-12-27 | Christmas+2 | 2 | NaN |
| 2025-12-28 | Christmas+3 | 3 | NaN |
| 2025-12-29 | NewYear-3 | 4 | -3 |
| 2025-12-30 | NewYear-2 | NaN | -2 |
| 2025-12-31 | NewYear-1 | NaN | -1 |
| 2026-01-01 | NewYear+0 | NaN | 0 |
Dec 29 is in both windows: 4 days after Christmas and 3 before New Year, so New Year wins the label, and both distance columns have a value. With return_offsets=False the label would be "Christmas, NewYear".
The same example with the default dummy output (return_offsets=True only) gives one column per label, ordered by holiday and then by offset:
| date | Christmas-2 | Christmas-1 | Christmas+0 | Christmas+1 | Christmas+2 | Christmas+3 | NewYear-3 | NewYear-2 | NewYear-1 | NewYear+0 |
|---|---|---|---|---|---|---|---|---|---|---|
| 2025-12-23 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2025-12-24 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2025-12-25 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2025-12-26 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2025-12-27 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 2025-12-28 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2025-12-29 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 2025-12-30 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 2025-12-31 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 2026-01-01 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
PR is open: https://github.com/sktime/sktime/pull/11314
Source: sktime/sktime