unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
7.9k stars 855 forks source link

`TFTModel.predict()` with `predict_likelihood_parameters=True` #2485

Open Marcrb2 opened 1 month ago

Marcrb2 commented 1 month ago

Hi, I’m trying to use the predict method from TFTModel with predict_likelihood_parameters=True, and the returned TimeSeries has static_covariates set to None.

However, if I call predict with predict_likelihood_parameters=False, the original static_covariates are kept.

Is this the expected behavior?

If so, how can I inverse transform the returned TimeSeries (given that during training, I used a Pipeline with a Scaler and StaticCovariatesTransformer)?

Now, without static_covariates, Pipeline.inverse_transform(TFTModel.predict(predict_likelihood_parameters=True), partial=True) is obviously failing.

dennisbader commented 1 month ago

Hi @Marcrb2, and thanks for writing.

For now this behavior was intentionally chosen (until we find a better way). The reason is that static covariates can be component/column specific (e.g. each column from your target series has a dedicated value for each static variable). Now, since predict_likelihood_parameters adds columns to the target series, there might be a mismatch between the number of output and input columns. To avoid having to repeat component-specific static covariates for each parameter, we chose to drop them for now.

But it would be good to find a better way handling it. I'll add it to our backlog.

dennisbader commented 1 month ago

Also on another point: If you generate the predictions with num_samples>>1 and predict_likelihood_parameters=False, then the static covariates are kept. You could then inverse transform the result, and afterwards compute the parameters on it (e.g. compute quantiles, mean, std, ... from the probabilistic TimeSeries).