Skip to content

[BUG] StackingEnsemble doesn't work with segment named target #1262

Closed
1 task done
Mr-Geekman opened this issue May 11, 2023 · 0 comments · Fixed by #1263
Closed
1 task done

[BUG] StackingEnsemble doesn't work with segment named target #1262

Mr-Geekman opened this issue May 11, 2023 · 0 comments · Fixed by #1263
Assignees
Labels
bug Something isn't working

Comments

@Mr-Geekman
Copy link
Contributor

🐛 Bug Report

If dataset has a segment named target there will be problem on using StackingEnsemble with backtest.

Expected behavior

Everything works fine.

It can be fixed by setting level for renaming of columns in StackingEnsemble._make_features.

How To Reproduce

Script:

from sklearn.ensemble import GradientBoostingRegressor

from etna.datasets import TSDataset, generate_ar_df
from etna.transforms import LagTransform, DateFlagsTransform
from etna.pipeline import Pipeline
from etna.models import ProphetModel, CatBoostMultiSegmentModel
from etna.ensembles import StackingEnsemble
from etna.metrics import MAE, SMAPE

HORIZON = 7


def get_ts() -> TSDataset:
    df = generate_ar_df(periods=100, start_time="2020-01-01", n_segments=5, freq="D")
    df.loc[df["segment"] == "segment_0", "segment"] = "target"
    df_wide = TSDataset.to_dataset(df)
    ts = TSDataset(df=df_wide, freq="D")
    return ts


def main():
    ts = get_ts()

    df_melt = ts
    model = ProphetModel()
    catboost_transforms = [LagTransform(in_column="target", lags=list(range(7, 20))), DateFlagsTransform()]
    pipeline = Pipeline(model=model, transforms=[], horizon=HORIZON)
    multicb_pipeline = Pipeline(transforms=catboost_transforms, model=CatBoostMultiSegmentModel(), horizon=HORIZON)

    stacking_ensemble = StackingEnsemble(pipelines=[pipeline, multicb_pipeline],
                                         final_model=GradientBoostingRegressor(), n_folds=5,
                                         n_jobs=4)
    _ = stacking_ensemble.backtest(df_melt, metrics=[MAE(), SMAPE()], n_folds=3, aggregate_metrics=True, n_jobs=2)


if __name__ == "__main__":
    main()

Environment

No response

Additional context

No response

Checklist

  • Bug appears at the latest library version
@Mr-Geekman Mr-Geekman added the bug Something isn't working label May 11, 2023
@github-project-automation github-project-automation bot moved this to Specification in etna board May 11, 2023
@Mr-Geekman Mr-Geekman moved this from Specification to Todo in etna board May 12, 2023
@martins0n martins0n moved this from Todo to In Progress in etna board May 17, 2023
malodetz added a commit that referenced this issue May 17, 2023
@malodetz malodetz self-assigned this May 17, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in etna board May 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants