VotingEnsemble

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

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

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([ts, prediction_interval, ...])

Make a forecast of the next points of a dataset.

load(path[, ts])

Load an object.

params_to_tune()

Get hyperparameter grid to tune.

predict(ts[, start_timestamp, ...])

Make in-sample predictions on dataset in a given range.

save(path)

Save the object.

set_params(**params)

Return new object instance with modified parameters.

to_dict()

Collect all information about etna object in dict.

Attributes

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

params_to_tune() Dict[str, etna.distributions.distributions.BaseDistribution][source]

Get hyperparameter grid to tune.

Not implemented for this class.

Returns

Grid with hyperparameters.

Return type

Dict[str, etna.distributions.distributions.BaseDistribution]