Closed joshuajnoble closed 9 months ago
Hi @joshuajnoble, I believe you might call the wrong model in your code.
From your error message:
---> 10 tcn_predict_output = model_nbeats.predict(test_length, past_covariates=cov_series, series=nbeats_test)
Could it be that you actually trained a TCNModel (just assuming from the tcn_predict_output
variable name)?
For me everything runs fine with the code below:
from darts.models import NBEATSModel
from darts.utils.timeseries_generation import sine_timeseries
series = sine_timeseries(length=30)
model_nbeats = NBEATSModel(
input_chunk_length=10,
output_chunk_length=10,
n_epochs=1,
)
model_nbeats.fit(
series=series,
past_covariates=series,
val_series=series,
val_past_covariates=series
)
model.predict(
n=10,
series=series,
past_covariates=series
)
Thank you very much for getting back to me. The tcn_predict_output
was just a copy/paste error, it’s only an array. Your code works for me and I’ve tracked down the source of the bug: I was training on a array of TimeSeries generated from TimeSeries.from_group_dataframe()
and that seems to be the source of the error. Fitting the model using NBEATSModel.fit()
on one TimeSeries from the array generated by TimeSeries.from_group_dataframe()
solves the error. I don’t think this is a bug necessarily but just an unclear error message. Should I close the bug?
Hi @joshuajnoble, TimeSeries.from_group_dataframe()
should also work fine.
NBEATSModel supports training/prediction on multiple TimeSeries:
import pandas as pd
from darts import TimeSeries
from darts.models import NBEATSModel
from darts.utils.timeseries_generation import sine_timeseries
# generate a DataFrame that has 2 groups with the same time index
df = pd.DataFrame(
{
"a": [i for i in range(60)],
"groups": [0] * 30 + [1] * 30,
},
index=pd.date_range("2000-01-01", periods=30, freq="D").tolist() * 2
)
# returns a list of 2 time series
series = TimeSeries.from_group_dataframe(df, group_cols="groups")
model_nbeats = NBEATSModel(
input_chunk_length=10,
output_chunk_length=10,
n_epochs=1,
)
# for simplicity we just past `series` as past covariates (in reality those should be different features)
# `past_covariates` expects a list of TimeSeries of the same length as `series`
model_nbeats.fit(
series=series,
past_covariates=series,
val_series=series,
val_past_covariates=series
)
# same here, returns list of with 2 forecasted TimeSeries
preds = model_nbeats.predict(
n=10,
series=series,
past_covariates=series
)
Hmm, interesting. I guess I’m setting up my arrays of TimeSeries incorrectly for NBEATS then. The same arrays of TimeSeries objects are fine with TCN, TFT, RegressionModel, and CatBoost models so perhaps I need to try re-reading the documentation for NBEATS more closely to see how it might be different.
I guess at this point the bug is really just about the error message that the model is spitting out, e.g. The model has been trained with future covariates.
Can you double check the type of model that raised this error just before calling predict? It really sounds like it's not actually an NBEATSModel.
isinstance(model, NBEATSModel)
# or
type(model)
Because NBEATSModel cannot be trained with future covariates -> prediction can never get executed.
It will raise the following error already when calling model.fit(..., future_covariates=series)
:
ValueError: Some future_covariates have been provided to a PastCovariates model. These models support only past_covariates.
All the other models you listed except TCNModel support future covariates for training and prediction. After being trained with future covariates, the prediction expects future covariates as well and will raise the error you mentioned if none were provided.
Let me know if it is indeed an NBEATSModel. If yes, then it is a bug on our side. Could you then provide a minimal reproducible example so that we can investigate this?
Describe the bug
When calling NBEATs predict() I get the following error:
Stack trace:
To Reproduce
The model configuration is as shown here:
Fitting is done as so:
Expected behavior A clear and concise description of what you expected to happen.
Since NBEATs models don’t support future_covariates this behavior is unexpected
System (please complete the following information):
Additional context Add any other context about the problem here.