PointReductionForecaster¶
yohou.point.PointReductionForecaster
¶
Bases: BaseReductionForecaster, BasePointForecaster
Point forecaster using sklearn estimators on tabularized time series.
Converts the time series point forecasting task to a tabular one.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
estimator
|
BaseEstimator
|
Point estimator used to fit the tabularized data. |
LinearRegression()
|
reduction_strategy
|
(direct, dir - rec, multi - output)
|
Strategy for multi-step forecasting. |
"direct"
|
target_transformer
|
BaseActualTransformer or None
|
Transformer for target preprocessing. |
None
|
actual_transformer
|
BaseActualTransformer or None
|
Transformer for feature engineering (typically LagTransformer). |
None
|
forecast_transformer
|
BaseForecastTransformer or None
|
Transformer applied to |
None
|
target_as_feature
|
(transformed, raw)
|
Whether to include the target variable as a feature for reduction.
If |
"transformed"
|
panel_strategy
|
('global', multivariate)
|
How to handle panel data. See |
"global"
|
nan_handling
|
(drop, 'pass')
|
How to handle NaN values in tabularized data.
|
"drop"
|
n_jobs
|
int or None
|
Number of jobs to run in parallel for the |
None
|
step_feature_alignment
|
(all, matched, cumulative)
|
Controls which step-indexed feature columns each direct estimator
sees. Only the
|
"all"
|
time_weighter
|
BaseWeighter or None
|
Per-timestep training-sample weighter (e.g.
|
None
|
vintage_weighter
|
BaseWeighter or None
|
Per-vintage training-sample weighter. Resolved via direct lookup at
observation time (no alignment strategy) and combined multiplicatively
with |
None
|
sample_weight_alignment
|
(first_step, mean_step, weighted_mean_step, max_weight_step, min_weight_step)
|
Strategy for converting |
"first_step"
|
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.point import PointReductionForecaster
>>>
>>> # Create simple time series data
>>> df = pl.DataFrame({
... "time": pl.datetime_range(
... start=datetime(2021, 1, 1), end=datetime(2021, 1, 10), interval="1d", eager=True
... ),
... "value": [10.0, 12.0, 15.0, 14.0, 16.0, 18.0, 20.0, 19.0, 21.0, 23.0],
... })
>>>
>>> # Split into train/test
>>> train = df[:8]
>>>
>>> # Create and fit forecaster
>>> forecaster = PointReductionForecaster()
>>> _ = forecaster.fit(y=train, forecasting_horizon=1)
>>>
>>> # Generate one-step prediction
>>> y_pred = forecaster.predict(forecasting_horizon=1)
>>> len(y_pred)
1
>>> sorted(y_pred.columns)
['time', 'value', 'vintage_time']
Notes ¶
Reduction strategies:
- Multi-output: A single model predicts all H horizon steps simultaneously. Simple and fast, but assumes the same model structure is appropriate for every step.
- Direct: H independent models, one per horizon step. Each model specialises in its own step, avoiding error accumulation from recursive prediction but ignoring inter-step dependencies.
- Dir-Rec (direct-recursive hybrid): H models are fitted sequentially. Model h predicts step h using the original features augmented with in-sample predictions from models 1 to h-1. This combines the specialised per-step training of the direct strategy with inter-step information flow.
For direct and dir-rec strategies, estimator_ becomes a
list[BaseEstimator] of length H (one per horizon step) instead
of a single estimator.
All strategies can be applied recursively for multi-step forecasting
beyond the fit horizon by specifying a larger forecasting horizon
during prediction, unless X_forecast was provided at fit time, in
which case predict raises a ValueError; use
ForecastedFeatureForecaster
for that case.
See Also ¶
BaseReductionForecaster: Base class for reduction forecasters.LagTransformer: Create lagged features for reduction strategies.
Source Code ¶
Source code in src/yohou/point/reduction.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
Methods ¶
fit(y, X_actual=None, forecasting_horizon=1, X_future=None, X_forecast=None, **params)
¶
Fit the forecaster to historical data.
Tabularizes the time series and fits the wrapped sklearn estimator.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y
|
DataFrame
|
Target time series with a |
required |
X_actual
|
DataFrame or None
|
Actual feature observations with a |
None
|
forecasting_horizon
|
int
|
Number of time steps to forecast into the future. |
1
|
X_future
|
DataFrame or None
|
Known future features with a |
None
|
X_forecast
|
DataFrame or None
|
External forecasts with |
None
|
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
self
|
The fitted forecaster instance. |
Raises ¶
| Type | Description |
|---|---|
ValueError
|
If |
Source Code ¶
Source code in src/yohou/point/reduction.py
Tutorials¶
The following example notebooks use this component:
-
Conformal Prediction Intervals
Build distribution-free prediction intervals with SplitConformalForecaster using calibration holdouts and configurable conformity scoring functions.
-
Decomposition
Chain PolynomialTrendForecaster, PatternSeasonalityForecaster, and FourierSeasonalityForecaster inside DecompositionPipeline with component visualisation.
-
Direct, Recursive, and MIMO Strategies
Compare direct, recursive, and MIMO reduction strategies across forecasting horizons to understand the trade-offs for your use case.
-
Exogenous Features (X_actual, X_future, X_forecast)
Build a forecasting model with actual observations, known-future indicators, and multi-vintage external forecasts on synthetic electricity price data.
-
Forecast Visualization
Visualise point forecasts from single and multiple models, decomposition pipeline components, and time weight decay functions with interactive Plotly.
-
Forecasting Workflow
Evaluate forecasters with cross-validation, search hyperparameters with GridSearchCV, and inspect residuals to diagnose model weaknesses.