# Ensembles notebook¶

This notebook contains the simple examples of using the ensemble models with ETNA library.

**Table of Contents**

```
[1]:
```

```
import warnings
warnings.filterwarnings("ignore")
```

## 1. Load Dataset¶

In this notebook we will work with the dataset contains only one segment with monthly wine sales. Working process with the dataset containing more segments will be absolutely the same.

```
[2]:
```

```
import pandas as pd
from etna.datasets import TSDataset
```

```
[3]:
```

```
original_df = pd.read_csv("data/monthly-australian-wine-sales.csv")
original_df["timestamp"] = pd.to_datetime(original_df["month"])
original_df["target"] = original_df["sales"]
original_df.drop(columns=["month", "sales"], inplace=True)
original_df["segment"] = "main"
original_df.head()
df = TSDataset.to_dataset(original_df)
ts = TSDataset(df=df, freq="MS")
ts.plot()
```

## 2. Build Pipelines¶

Given the sales’ history, we want to select the best model(pipeline) to forecast future sales.

```
[4]:
```

```
from etna.pipeline import Pipeline
from etna.models import NaiveModel, SeasonalMovingAverageModel, CatBoostModelMultiSegment
from etna.transforms import LagTransform
from etna.metrics import MAE, MSE, SMAPE, MAPE
HORIZON = 3
N_FOLDS = 5
```

Let’s build four pipelines using the different models

```
[5]:
```

```
naive_pipeline = Pipeline(model=NaiveModel(lag=12), transforms=[], horizon=HORIZON)
seasonalma_pipeline = Pipeline(
model=SeasonalMovingAverageModel(window=5, seasonality=12), transforms=[], horizon=HORIZON
)
catboost_pipeline = Pipeline(
model=CatBoostModelMultiSegment(),
transforms=[LagTransform(lags=[6, 7, 8, 9, 10, 11, 12], in_column="target")],
horizon=HORIZON,
)
pipeline_names = ["naive", "moving average", "catboost"]
pipelines = [naive_pipeline, seasonalma_pipeline, catboost_pipeline]
```

And evaluate their performance on the backtest

```
[6]:
```

```
metrics = []
for pipeline in pipelines:
metrics.append(
pipeline.backtest(
ts=ts, metrics=[MAE(), MSE(), SMAPE(), MAPE()], n_folds=N_FOLDS, aggregate_metrics=True, n_jobs=5
)[0].iloc[:, 1:]
)
metrics = pd.concat(metrics)
metrics.index = pipeline_names
metrics
```

```
[Parallel(n_jobs=5)]: Using backend MultiprocessingBackend with 5 concurrent workers.
[Parallel(n_jobs=5)]: Done 1 tasks | elapsed: 6.3s
[Parallel(n_jobs=5)]: Done 2 out of 5 | elapsed: 12.0s remaining: 17.9s
[Parallel(n_jobs=5)]: Done 3 out of 5 | elapsed: 17.0s remaining: 11.3s
[Parallel(n_jobs=5)]: Done 5 out of 5 | elapsed: 26.2s remaining: 0.0s
[Parallel(n_jobs=5)]: Done 5 out of 5 | elapsed: 26.2s finished
[Parallel(n_jobs=5)]: Using backend MultiprocessingBackend with 5 concurrent workers.
[Parallel(n_jobs=5)]: Done 1 tasks | elapsed: 5.0s
[Parallel(n_jobs=5)]: Done 2 out of 5 | elapsed: 9.7s remaining: 14.6s
[Parallel(n_jobs=5)]: Done 3 out of 5 | elapsed: 16.5s remaining: 11.0s
[Parallel(n_jobs=5)]: Done 5 out of 5 | elapsed: 28.1s remaining: 0.0s
[Parallel(n_jobs=5)]: Done 5 out of 5 | elapsed: 28.1s finished
[Parallel(n_jobs=5)]: Using backend MultiprocessingBackend with 5 concurrent workers.
[Parallel(n_jobs=5)]: Done 1 tasks | elapsed: 5.9s
[Parallel(n_jobs=5)]: Done 2 out of 5 | elapsed: 11.4s remaining: 17.0s
[Parallel(n_jobs=5)]: Done 3 out of 5 | elapsed: 16.7s remaining: 11.1s
[Parallel(n_jobs=5)]: Done 5 out of 5 | elapsed: 28.8s remaining: 0.0s
[Parallel(n_jobs=5)]: Done 5 out of 5 | elapsed: 28.8s finished
```

```
[6]:
```

MAE | MSE | SMAPE | MAPE | |
---|---|---|---|---|

naive | 2437.466667 | 1.089199e+07 | 9.949886 | 10.222106 |

moving average | 1913.826667 | 6.113701e+06 | 7.897570 | 7.824056 |

catboost | 2271.766726 | 8.923741e+06 | 9.376638 | 10.013138 |

## 3. Ensembles¶

To improve the performance of the individual models, we can try to make ensembles out of them. Our library contains two ensembling methods, which we will try on now.

### 3.1 VotingEnsemble¶

`VotingEnsemble`

forecasts future values with weighted averaging of it’s `pipelines`

forecasts.

```
[7]:
```

```
from etna.ensembles import VotingEnsemble
```

By default, `VotingEnsemble`

uses **uniform** weights for the pipelines’ forecasts. However, you can specify the weights manually using the `weights`

parameter. The higher weight the more you trust the base model.

*Note*: The `weights`

are automatically normalized.

```
[8]:
```

```
voting_ensemble = VotingEnsemble(pipelines=pipelines, weights=[1, 9, 4], n_jobs=4)
```

```
[9]:
```

```
voting_ensamble_metrics = voting_ensemble.backtest(
ts=ts, metrics=[MAE(), MSE(), SMAPE(), MAPE()], n_folds=N_FOLDS, aggregate_metrics=True, n_jobs=2
)[0].iloc[:, 1:]
voting_ensamble_metrics.index = ["voting ensemble"]
voting_ensamble_metrics
```

```
[Parallel(n_jobs=2)]: Using backend MultiprocessingBackend with 2 concurrent workers.
[Parallel(n_jobs=2)]: Done 1 tasks | elapsed: 6.6s
[Parallel(n_jobs=2)]: Done 2 tasks | elapsed: 11.7s
[Parallel(n_jobs=2)]: Done 3 out of 5 | elapsed: 11.7s remaining: 7.8s
[Parallel(n_jobs=2)]: Done 5 out of 5 | elapsed: 12.8s remaining: 0.0s
[Parallel(n_jobs=2)]: Done 5 out of 5 | elapsed: 12.8s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
```

```
[9]:
```

MAE | MSE | SMAPE | MAPE | |
---|---|---|---|---|

voting ensemble | 1972.207943 | 6.685831e+06 | 8.172377 | 8.299714 |

### 3.2 StackingEnsemble¶

`StackingEnsemble`

forecasts future using the metamodel to combine the forecasts of it’s `pipelines`

.

```
[10]:
```

```
from etna.ensembles import StackingEnsemble
```

By default, `StackingEnsemble`

uses only the pipelines’ forecasts as features for the `final_model`

. However, you can specify the additional features using the `features_to_use`

parameter. The following values are possible: + **None** - use only the pipelines’ forecasts(default) + **List[str]** - use the pipelines’ forecasts + features from the list + **“all”** - use all the available features

*Note:* It is possible to use only the features available for the base models.

```
[11]:
```

```
stacking_ensemble_unfeatured = StackingEnsemble(pipelines=pipelines, n_folds=10, n_jobs=4)
```

```
[12]:
```

```
stacking_ensamble_metrics = stacking_ensemble_unfeatured.backtest(
ts=ts, metrics=[MAE(), MSE(), SMAPE(), MAPE()], n_folds=N_FOLDS, aggregate_metrics=True, n_jobs=2
)[0].iloc[:, 1:]
stacking_ensamble_metrics.index = ["stacking ensemble"]
stacking_ensamble_metrics
```

```
[Parallel(n_jobs=2)]: Using backend MultiprocessingBackend with 2 concurrent workers.
[Parallel(n_jobs=2)]: Done 1 tasks | elapsed: 14.9s
[Parallel(n_jobs=2)]: Done 2 tasks | elapsed: 22.5s
[Parallel(n_jobs=2)]: Done 3 out of 5 | elapsed: 25.7s remaining: 17.1s
[Parallel(n_jobs=2)]: Done 5 out of 5 | elapsed: 36.4s remaining: 0.0s
[Parallel(n_jobs=2)]: Done 5 out of 5 | elapsed: 36.4s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 1.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 1.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 2.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 3.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 3.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 4.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 5.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 6.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 7.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.2s finished
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.5s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.5s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 1.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 1.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 2.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 3.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 3.9s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 4.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 5.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 6.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 7.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.4s finished
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.8s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.8s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 1.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 1.0s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.4s finished
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.3s finished
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 1.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 1.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 2.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 2.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 3.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 4.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 5.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 5.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 6.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 7.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 7.3s finished
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 8.4s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 8.4s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.8s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.8s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 1.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 1.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 2.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 3.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 4.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 5.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 5.9s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 6.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 7.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.2s finished
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.7s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.7s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.9s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 0.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 0.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 0.4s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 0.5s finished
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 1.2s remaining: 0.0s
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 0.8s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 2 out of 2 | elapsed: 1.6s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 3 out of 3 | elapsed: 2.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 4 out of 4 | elapsed: 3.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 5 out of 5 | elapsed: 4.3s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 6 out of 6 | elapsed: 5.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 7 out of 7 | elapsed: 6.1s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 8 out of 8 | elapsed: 6.9s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 9 out of 9 | elapsed: 7.7s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.5s remaining: 0.0s
[Parallel(n_jobs=1)]: Done 10 out of 10 | elapsed: 8.5s finished
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.8s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 9.8s finished
/Users/d.a.binin/Library/Caches/pypoetry/virtualenvs/etna-5hbqKzTr-py3.8/lib/python3.8/site-packages/joblib/parallel.py:735: UserWarning: Multiprocessing-backed parallel loops cannot be nested, setting n_jobs=1
n_jobs = self._backend.configure(n_jobs=self.n_jobs, parallel=self,
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.7s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.7s finished
[Parallel(n_jobs=4)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=4)]: Done 1 out of 1 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 2 out of 2 | elapsed: 0.0s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s remaining: 0.0s
[Parallel(n_jobs=4)]: Done 3 out of 3 | elapsed: 0.1s finished
```

```
[12]:
```

MAE | MSE | SMAPE | MAPE | |
---|---|---|---|---|

stacking ensemble | 2058.487868 | 8.182131e+06 | 8.508705 | 8.50082 |

In addition, it is also possible to specify the `final_model`

. You can use any regression model with the sklearn interface for this purpose.

### 3.3 Results¶

Finally, let’s take a look at the results of our experiments

```
[13]:
```

```
metrics = pd.concat(
[
metrics,
voting_ensamble_metrics,
stacking_ensamble_metrics
]
)
metrics
```

```
[13]:
```

MAE | MSE | SMAPE | MAPE | |
---|---|---|---|---|

naive | 2437.466667 | 1.089199e+07 | 9.949886 | 10.222106 |

moving average | 1913.826667 | 6.113701e+06 | 7.897570 | 7.824056 |

catboost | 2271.766726 | 8.923741e+06 | 9.376638 | 10.013138 |

voting ensemble | 1972.207943 | 6.685831e+06 | 8.172377 | 8.299714 |

stacking ensemble | 2058.487868 | 8.182131e+06 | 8.508705 | 8.500820 |