Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForecasterAutoreg fails to fit when exog do not have string column names #575

Open
yarnabrina opened this issue Oct 23, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@yarnabrina
Copy link

MCVE

import numpy
import pandas

numpy.random.seed(seed=0)

data = pandas.DataFrame(numpy.random.random(size=3 * 20).reshape((20, 3)))

from sklearn.linear_model import LinearRegression
regressor = LinearRegression()

from skforecast.ForecasterAutoreg import ForecasterAutoreg
forecaster = ForecasterAutoreg(regressor, 1)

forecaster.fit(data.iloc[:, 0], exog=data.iloc[:, 1:])  # fails
forecaster.fit(data.iloc[:, 0], exog=data.iloc[:, 1:].rename(columns={1: "x1", 2: "x2"}))  # works

Error

TypeError: Feature names are only supported if all input features have string names, but your input has ['int', 'str'] as feature name / column name types. If you want feature names to be stored and validated, you must convert them all to strings, by using X.columns = X.columns.astype(str) for example. Otherwise you can remove feature / column names from your input data, or convert them all to a non-string data type.

Expectation

The expectation was that both should work identically and successfully. I think the error is caused because passed column names are integers (by default), and skforecast is trying to add more columns corresponding to lags which has string column names.

(Found as part of sktime/sktime#5447)

@JavierEscobarOrtiz
Copy link
Collaborator

Hello @yarnabrina

Thanks for opening the issue, we really appreciate it.

The error seems to occur during the sickit-learn regressor.fit(), the feature names (columns) must be of the same type.

For example, if you use a LGBMRegressor, everything works.

We will evaluate it 😄

Thank you!

@JavierEscobarOrtiz JavierEscobarOrtiz added the enhancement New feature or request label Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants