Nixtla / neuralforecast

Scalable and user friendly neural :brain: forecasting algorithms.
https://nixtlaverse.nixtla.io/neuralforecast
Apache License 2.0
2.93k stars 336 forks source link

NeuralForecast.predict() sets the unique_id column as an index #831

Closed merrittkowaleski closed 9 months ago

merrittkowaleski commented 9 months ago

What happened + What you expected to happen

We expect the unique_id column in the dataframe returned by predict() to behave as a normal column, since that's what it is in input. However, it's being output as an index.

It can be worked around by running reset_index() on the dataframe returned by predict, but it is unintuitive that that needs to be done.

Versions / Dependencies

neuralforecast==1.6.4

Reproduction script

from neuralforecast import NeuralForecast
from neuralforecast.models import NBEATS
from neuralforecast.utils import AirPassengersDF

df = AirPassengersDF
train_df = df[df.ds <= '1959-12-31']
horizon = 12
nf = NeuralForecast(
    models=[NBEATS(input_size=2 * horizon, h=horizon, max_steps=50)],
    freq='M')
nf.fit(df=train_df)
got = nf.predict() 

Expected result: set(got.columns) == {'unique_id', 'ds', 'NBEATS'}

Actual result: set(got.columns) == {'ds', 'NBEATS'}

Issue Severity

Low: It annoys or frustrates me.

jmoralez commented 9 months ago

Hey. We're deprecating this behavior and in the next release we'll have a configuration that will allow you to get the id as a column in the output, i.e. adding the following:

import neuralforecast

neuralforecast.config.id_as_index = False

will return the id as a column from the predict, predict_insample and cross_validation methods.

I'm closing this since it has already been addressed.