timeseriesAI / tsai

Time series Timeseries Deep Learning Machine Learning Python Pytorch fastai | State-of-the-art Deep Learning library for Time Series and Sequences in Pytorch / fastai
https://timeseriesai.github.io/tsai/
Apache License 2.0
5.3k stars 661 forks source link

interpretability #585

Closed Jalagarto closed 1 year ago

Jalagarto commented 2 years ago

Is there any way of achieving "XCMPlus" to show model rules?

Anchors rules, shape values or LIME wouldn't work for me, since they show rules only for one value. Maybe if I could apply it to multiple values at the same time would be great, so I can train one model and get rules for different set of points. Example:

rules = get_rules(Xtrain['new instances'])

learn.feature_importance(feature_names=var_list)
learn.step_importance() # only for explainable AI?

and learn.show_gradcam(xb[0], yb[0]) but I need a set of rules for recommendations of which variables need to be changed

something similar of what Autogluon predictor.print_interpretable_rules(model_name='RuleFit') does but for Time Series Classification and able to be used for multiple instances at the same time (this could be actually be done by averaging results of all instances with this characteristics, so it's not a big deal for me to do it).

> ------------------------------
> RuleFit:
>       Predictions are made by summing the coefficients of each rule
> ------------------------------
                                           rule  coef
                                             V1  0.00
         RotorSpeed <= 12.99 and V1 > 561.10001  0.02
                         RotorSpeed <= 12.65667  0.02
RotorSpeed <= 14.53364 and TempAmbient <= 19.85  0.01
          RotorSpeed > 12.58077 and V1 > 576.25 -0.01
RotorSpeed <= 22.84495 and WindSpeed > 10.60625  0.02
     TempAmbient > 10.65 and WindSpeed <= 14.25 -0.02

I would be happy to help developing a solution, since it is in my own benefit.

Thanks a lot for the good work!

oguiza commented 2 years ago

Hi @Jalagarto, I'm not quite sure I understand what you mean by model rules. Could you please help me understand what you'd expect to get?

zmce2018 commented 2 years ago

@Jalagarto are you looking for a local explainer, which explains how each decision on different time steps is made?

oguiza commented 1 year ago

Closed due to lack of response.

Jalagarto commented 1 year ago

Hi @Jalagarto, I'm not quite sure I understand what you mean by model rules. Could you please help me understand what you'd expect to get?

Hi. Sorry for the late reply @oguiza. I didn't see the notification. So the same idea of anchors (where it explains what values of what variables had more impact in the prediction), but for a set of points. Similar to forests decision rules or global surrogate models. This way I could recommend which values of the which variables would maximize the chances to get a desired prediction. I.e., windspeed > 6m/s would maximaze the chances of a windturbine's reset to be successful.

This is not a measure for one prediction point, but a more general rule.

I have sorted it out by calculating and analyzing the KDE, MLE, quantiles etc. of success and failure (Boolean values of target variable) subsets of the most important feature for different subsets (test, train, all, valid, or subset of test data points). When doing that I could also play with the time window I want to analyse.

Thanks for the great work. It's really impressive and I am enjoying a lot fine tuning the TS classification model.

Jalagarto commented 1 year ago

@Jalagarto are you looking for a local explainer, which explains how each decision on different time steps is made?

No @zmce2018, I need global explanations, so shapely values won't make it. I think I would need something like a global surrogate, with the advantages of Deep TS Classification (since forests seem to be overall less accurate).

Thx for your answer