sktime / sktime

A unified framework for machine learning with time series
https://www.sktime.net
BSD 3-Clause "New" or "Revised" License
7.98k stars 1.38k forks source link

[ENH] resolve redundant broadcasting code in `TransformedTargetForecaster._get_inverse_transform` etc #4688

Open fkiraly opened 1 year ago

fkiraly commented 1 year ago

As @benHeid pointed out, there may be some redundant code in TransformedTargetForecaster._get_inverse_transform, which seems to duplicate column broadcasting for transformers.

Possibly it is needed to deal with column multi-index (which transformers cannot necessarily), but that may be something to revisit as a part of BaseTransformer.

This issue is for investigating whether there is duplication to be resolved.

benHeid commented 1 year ago

Just directly calling inverse_transform would not work; this would cause an error on line 150 in base.py when calling X = X.combine_first(X_update) with the error message ValueError: cannot join with no overlapping index names

The reason is that in the probabilistic case X looks as:

         Coverage             
              0.9             
            lower        upper
1959  -488.285569  1953.243863
1960   -22.106610  2460.082626
1961  -561.797409  1921.745799
1962  1419.392842  3902.981509

and X_update as

       TOTEMP
1958  66513.0

Thereby X are the values after the probabilistic forecast that should be inverse transformed X_update is a cutout from self._X. The combine_first fails in that case since the column names differ. An Optionsmight be to create a df from X_update with the correct column names, however this might cause problems with multivariate forecasting.