scikit-hts icon indicating copy to clipboard operation
scikit-hts copied to clipboard

[BUG] SarimaxModel fails with to fit with exogenous data

Open jstammers opened this issue 2 years ago • 0 comments

Describe the bug I am failing to fit a SarimaxModel because the model reports that the exogenous and endogenous dataframes do not have the same index despite coming from the same dataframe.

After debugging, this seems to be due to the fact that the _get_transformed_data method does not preserve the index using the default transformer

I have been able to correct this using

    def _get_transformed_data(
        self, as_series: bool = False
    ) -> Union[pandas.DataFrame, pandas.Series]:
        key = self.node.key
        value = self.node.item
        transformed = self.transform_function.transform(value[key])
        if as_series:
            return pandas.Series(transformed, index=value[key].index)
        else:
            return pandas.DataFrame({key: transformed})

But perhaps it would be better to modify FunctionTransformer.transform

    def transform(self, x: pandas.Series):
        return self.func(x.values)

as this does not preserve the index of the input series

To Reproduce

from hts.model import SarimaxModel
tree = ...
model = SarimaxModel(node=tree)

#raises ValueError: The indices for endog and exog are not aligned Expected behavior No error should be raised because the two dataframes should have the same index

jstammers avatar May 12 '22 18:05 jstammers