RegressionEnsembleModelWrapper
Python template · sinapsis_darts_forecasting.templates.time_series_model
Overview
Base Template for Darts Time Series forecasting models.
RegressionEnsembleModel — inherited documentation
Abstract base class for ensemble models. Ensemble models take in a list of forecasting models and ensemble their predictions to make a single one according to the rule defined by their `ensemble()` method.
If `future_covariates` or `past_covariates` are provided at training or inference time, they will be passed only to the models supporting them.
Parameters ---------- forecasting_models List of forecasting models whose predictions to ensemble
.. note:: if all the models are probabilistic, the `EnsembleModel` will also be probabilistic. .. train_num_samples Number of prediction samples from each forecasting model for multi-level ensembles. The n_samples dimension will be reduced using the `train_samples_reduction` method. train_samples_reduction If `forecasting_models` are probabilistic and `train_num_samples` > 1, method used to reduce the samples dimension to 1. Possible values: "mean", "median" or float value corresponding to the desired quantile. train_forecasting_models If set to `False`, the `forecasting_models` are not retrained when calling `fit()` (only supported if all the `forecasting_models` are pretrained `GlobalForecastingModels`). Default: ``True``. train_n_points The number of points per series to use to train the ensemble model. Can be set to `-1` to use the entire series to train the regressor if `forecasting_models` are already fitted and `train_forecasting_models=False`. show_warnings Whether to show warnings related to models covariates support. Use a regression model for ensembling individual models' predictions using the stacking technique [1]_.
The provided regression model must implement ``fit()`` and ``predict()`` methods (e.g. scikit-learn regression models). Note that here the regression model is used to learn how to best ensemble the individual forecasting models' forecasts. It is not the same usage of regression as in :class:`SKLearnModel`, where the regression model is used to produce forecasts based on the lagged series.
If `future_covariates` or `past_covariates` are provided at training or inference time, they will be passed only to the forecasting models supporting them.
If `forecasting_models` contains exclusively GlobalForecastingModels, they can be pre-trained. Otherwise, the `forecasting_models` must be untrained.
The regression model does not leverage the covariates passed to ``fit()`` and ``predict()``.
Parameters ---------- forecasting_models List of forecasting models whose predictions to ensemble regression_train_n_points The number of points per series to use to train the regression model. Can be set to `-1` to use the entire series to train the regressor if `forecasting_models` are already fitted and `train_forecasting_models=False`. regression_model Any regression model with ``predict()`` and ``fit()`` methods (e.g. from scikit-learn) Default: ``darts.models.LinearRegressionModel(fit_intercept=False)``
.. note:: if `regression_model` is probabilistic, the `RegressionEnsembleModel` will also be probabilistic. .. regression_train_num_samples Number of prediction samples from each forecasting model to train the regression model (samples are averaged). Should be set to 1 for deterministic models. Default: 1.
.. note:: if `forecasting_models` contains a mix of probabilistic and deterministic models, `regression_train_num_samples` will be passed only to the probabilistic ones. .. regression_train_samples_reduction If `forecasting_models` are probabilistic and `regression_train_num_samples` > 1, method used to reduce the samples before passing them to the regression model. Possible values: "mean", "median" or float value corresponding to the desired quantile. Default: "median" train_forecasting_models If set to `False`, the `forecasting_models` are not retrained when calling `fit()` (only supported if all the `forecasting_models` are pre-trained `GlobalForecastingModels`). Default: ``True``. train_using_historical_forecasts If set to `True`, use `historical_forecasts()` to generate the forecasting models' predictions used to train the regression model in `fit()`. Available when `forecasting_models` contains only `GlobalForecastingModels`. Recommended when `regression_train_n_points` is greater than `output_chunk_length` of the underlying `forecasting_models`. Default: ``False``. show_warnings Whether to show warnings related to forecasting_models covariates support. References ---------- .. [1] D. H. Wolpert, “Stacked generalization”, Neural Networks, vol. 5, no. 2, pp. 241–259, Jan. 1992
Examples -------- >>> from darts.datasets import AirPassengersDataset >>> from darts.models import RegressionEnsembleModel, NaiveSeasonal, LinearRegressionModel >>> series = AirPassengersDataset().load() >>> model = RegressionEnsembleModel( >>> forecasting_models = [ >>> NaiveSeasonal(K=12), >>> LinearRegressionModel(lags=4) >>> ], >>> regression_train_n_points=20 >>> ) >>> model.fit(series) >>> pred = model.predict(6) >>> print(pred.values()) [[494.24050364] [464.3869697 ] [496.53180506] [544.82269341] [557.35256055] [630.24334385]]
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-darts-forecasting==1.0.0uv pip install sinapsis-darts-forecasting==1.0.0uv add sinapsis-darts-forecasting==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Optional
Default: false
Optional
Default: 10
Required
Default: null
Optional
Default: true
Optional
Default: null
Optional
Default: null
Optional
Default: true
Optional
Default: null
Optional
Default: 1
Optional
Default: false
Optional
Default: "median"
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "RegressionEnsembleModelWrapper"
class_name: "RegressionEnsembleModelWrapper"
attributes:
validation_mode: false
forecast_horizon: 10
regressionensemblemodel_init:
show_warnings: true
regression_model: null
forecasting_models: null
train_forecasting_models: true
regression_train_n_points: null
regression_train_num_samples: 1
train_using_historical_forecasts: false
regression_train_samples_reduction: "median"
View original docstring example
The source example references XGBModelWrapper, not RegressionEnsembleModelWrapper.
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: XGBModelWrapper
class_name: XGBModelWrapper
template_input: InputTemplate
attributes:
forecast_horizon: 100
xgbmodel_init:
lags: 30
lags_past_covariates: 30
output_chunk_length: 100
random_state: 42
n_estimators: 200
learning_rate: 0.1
max_depth: 6
For a full list of options use the sinapsis cli: sinapsis info --all-template-names.
If you want to see all available models, please visit:
https://unit8co.github.io/darts/generated_api/darts.models.forecasting.htmlInheritance
sinapsis_darts_forecasting.templates.time_series_model.TimeSeriesModelEnvironment variables
Environment definitions belong to their canonical Python modules.