Nixtla / neuralforecast

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

Unable to explain NeuralForecast model with SHAP #996

Open MyAdminC opened 4 months ago

MyAdminC commented 4 months ago

Description

Hello, I'm trying to use the NeuralForecast model, which works really well, Thanks a lot.

But I've recently run into an issue where I can't use shap to interpret: nf = NeuralForecast(models=[NHITS_modle], freq=1)

I think this may be because the model itself is encapsulated by NeuralForecast. Because I've seen shap used in Mlforecast, and that work well.

I tried using the following code:

X = Y_df.drop(columns=['unique_id', 'ds', 'y']) X100 = shap.utils.sample(X, 100)

explainer = shap.Explainer(nf.models[0].predict, X100) shap_values = explainer(X)

But the last line throws up all sorts of errors, Any advice would be greatly appreciated!

Use case

No response