PolynomialTrendForecaster¶
yohou.stationarity.PolynomialTrendForecaster
¶
Bases: _BaseTrendForecaster
Forecast using polynomial trend extrapolation with ElasticNet regularization.
Fits a polynomial of specified degree to the historical data using ElasticNet regression and extrapolates into the future. Linear trend is the special case with degree=1.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
degree
|
int
|
Polynomial degree. degree=1 gives linear trend, degree=2 quadratic, etc. Higher degrees can overfit - typically use degree <= 3. |
1
|
estimator
|
RegressorMixin or None
|
Regression model used to fit polynomial coefficients. |
None
|
target_transformer
|
BaseActualTransformer
|
Transformer for target variable (e.g., LogTransformer). |
None
|
panel_strategy
|
('global', multivariate)
|
How to handle panel data. See |
"global"
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
estimator_ |
Pipeline
|
Fitted sklearn Pipeline with a polynomial feature transformer and a
clone of the provided |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.stationarity import PolynomialTrendForecaster
>>>
>>> # Create time series with linear trend
>>> y = pl.DataFrame({
... "time": pl.datetime_range(
... start=datetime(2020, 1, 1), end=datetime(2020, 12, 31), interval="1d", eager=True
... ),
... "value": range(366),
... })
>>>
>>> # Fit linear trend forecaster
>>> forecaster = PolynomialTrendForecaster(degree=1)
>>> forecaster.fit(y, forecasting_horizon=7)
PolynomialTrendForecaster()
>>>
>>> # Forecast next 7 days
>>> y_pred = forecaster.predict(forecasting_horizon=7)
See Also ¶
PatternSeasonalityForecaster: Seasonal pattern extraction for periodic components.FourierSeasonalityForecaster: Fourier-based seasonality estimation.DecompositionPipeline: Combines trend + seasonality + residual forecasters.
Notes ¶
- For exponential trends, consider using target_transformer=LogTransformer() with degree=1
- Polynomial trends can overfit - use with caution (typically degree <= 3)
- Time is converted to numeric values (number of intervals since first observation)
References ¶
- Hyndman, R.J., & Athanasopoulos, G. (2021). "Forecasting: principles and practice," 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3. Chapters 3.2 and 7.4.
Source Code ¶
Source code in src/yohou/stationarity/trend.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 | |
Tutorials¶
The following example notebooks use this component:
-
Decomposition
Chain PolynomialTrendForecaster, PatternSeasonalityForecaster, and FourierSeasonalityForecaster inside DecompositionPipeline with component visualisation.
-
Forecast Visualization
Visualise point forecasts from single and multiple models, decomposition pipeline components, and time weight decay functions with interactive Plotly.
-
How to Apply Stationarity to Panel Data
Apply per-group stationarity transforms on panel data with SeasonalDifferencing, DecompositionPipeline (polynomial trend + pattern seasonality), and residuals.
-
How to Build Panel Feature Pipelines
Combine ColumnForecaster, FeaturePipeline, FeatureUnion, and DecompositionPipeline on panel data with per-group scoring on KDD Cup air quality.
-
How to Build a Feature Pipeline
Nest FeaturePipeline, FeatureUnion, and DecompositionPipeline for multi-level feature engineering with trend-season-residual decomposition.
-
How to Choose a Decomposition Strategy
Build 2- and 3-component DecompositionPipeline forecasters chaining trend, seasonality, and residual models with target pre-transformation.