VotingEnsemble

class VotingEnsemble(pipelines: List[etna.pipeline.base.BasePipeline], weights: Optional[Union[List[float], Literal['auto']]] = None, regressor: Union[sklearn.tree._classes.DecisionTreeRegressor, sklearn.tree._classes.ExtraTreeRegressor, sklearn.ensemble._forest.RandomForestRegressor, sklearn.ensemble._forest.ExtraTreesRegressor, sklearn.ensemble._gb.GradientBoostingRegressor, catboost.core.CatBoostRegressor] = RandomForestRegressor(n_estimators=5), n_folds: int = 3, n_jobs: int = 1, joblib_params: Optional[Dict[str, Any]] = None)[source]

Bases: etna.pipeline.base.BasePipeline, etna.ensembles.base.EnsembleMixin

VotingEnsemble is a pipeline that forecast future values with weighted averaging of it’s pipelines forecasts.

Examples

>>> from etna.datasets import generate_ar_df
>>> from etna.datasets import TSDataset
>>> from etna.ensembles import VotingEnsemble
>>> from etna.models import NaiveModel
>>> from etna.models import ProphetModel
>>> from etna.pipeline import Pipeline
>>> df = generate_ar_df(periods=30, start_time="2021-06-01", ar_coef=[1.2], n_segments=3)
>>> df_ts_format = TSDataset.to_dataset(df)
>>> ts = TSDataset(df_ts_format, "D")
>>> prophet_pipeline = Pipeline(model=ProphetModel(), transforms=[], horizon=7)
>>> naive_pipeline = Pipeline(model=NaiveModel(lag=10), transforms=[], horizon=7)
>>> ensemble = VotingEnsemble(
...     pipelines=[prophet_pipeline, naive_pipeline],
...     weights=[0.7, 0.3]
... )
>>> _ = ensemble.fit(ts=ts)
>>> forecast = ensemble.forecast()
>>> forecast
segment         segment_0        segment_1       segment_2
feature            target           target          target
timestamp
2021-07-01          -8.84          -186.67          130.99
2021-07-02          -8.96          -198.16          138.81
2021-07-03          -9.57          -212.48          148.48
2021-07-04         -10.48          -229.16          160.13
2021-07-05         -11.20          -248.93          174.39
2021-07-06         -12.47          -281.90          197.82
2021-07-07         -13.51          -307.02          215.73

Init VotingEnsemble.

Parameters
Raises

ValueError: – If the number of the pipelines is less than 2 or pipelines have different horizons.

Inherited-members

Methods

backtest(ts, metrics[, n_folds, mode, ...])

Run backtest with the pipeline.

fit(ts)

Fit pipelines in ensemble.

forecast([prediction_interval, quantiles, ...])

Make predictions.

fit(ts: etna.datasets.tsdataset.TSDataset) etna.ensembles.voting_ensemble.VotingEnsemble[source]

Fit pipelines in ensemble.

Parameters

ts (etna.datasets.tsdataset.TSDataset) – TSDataset to fit ensemble

Returns

Fitted ensemble

Return type

self