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.91k stars 858 forks source link

Shap explanation for recursive multi-step forecasting #2488

Open ncooder opened 1 month ago

ncooder commented 1 month ago

Shapley explanation works for the whole prediction set, however sometimes one needs to explain every step in the forecasting. This is a complex issue due to using different approaches - direct or recursive models. Is there a way to do it step-by-step for the whole horizon?

madtoinou commented 1 month ago

Hi @ncooder,

I am not sure to understand what you mean but you can find some information about explanability with Darts here.

The explain() method for example, allows you to specify a foreground series, which can be different than the series used during training, and get insights about this specific forecast. You can also tweak the number of explained steps with the horizons argument.

Let me know if it answers you questions.

ncooder commented 4 weeks ago

@madtoinou Thank you for your response. I am implementing a recursive multi-step forecasting model for n-step ahead predictions. It involves iteratively forecasting one step ahead, adding each prediction into the dataset, and repeating with the same model.

My concern is the interpretation of shap explanation in this context. It is unclear for me whether shap in darts explains each one-step-ahead prediction individually or provides a global explanation for the entire n-step forecast.

madtoinou commented 2 weeks ago

Since each iteration consists in forecasting only one step, the Darts implementation of shap should explain each one-step-ahead prediction. You can think of it as the explainer is bound to the model which was defined with output_chunk_length=1, hence, it is not able to do anything in the context of the recursive multi-step forecasting that you are applying on top of the original forecasting model. It would however work in the context of "direct" inference with a model defined using output_chunk_length=desired_horizon.

It might be possible to use shap in the context of recursive prediction but it's not yet implemented in Darts.

ncooder commented 2 weeks ago

@madtoinou Thank you for your reply. This is what I was asking for. If there is not an existing solution, please mark it as a feature that can be introduced in future versions of darts.