fzi-forschungszentrum-informatik / TSInterpret

An Open-Source Library for the interpretability of time series classifiers
BSD 3-Clause "New" or "Revised" License
115 stars 8 forks source link

NativeGuideCF(method=NG) can return a CF of the same class. #37

Closed hugo-rddi closed 1 year ago

hugo-rddi commented 1 year ago

Hello, As is it mentioned in this issue's title, I have tried many times the current CF generation in this configuration, and it often generates a CF of the same label than the one predicted already by the the model.

Hope the issue is clear enough ! Thanks

JHoelli commented 1 year ago

Hi,

Looking at your last issue, I think the issue might have been that the input for y into the explain function is an array, although it is supposed to be an int. I rechecked the code and their is a small error in the notebooks for NunCF. I fixed that error and made NG more robust by changing some of the preprocessing code.

You can try it with: pip install https://github.com/fzi-forschungszentrum-informatik/TSInterpret/archive/refs/heads/ng_test.zip

or instead by adding:

cf_ts, cf_label = exp_model.explain(
    input_x,
    np.argmax(y_target, axis=1)**[0]**
)

Let me know if it works or if you still need help.

hugo-rddi commented 1 year ago

Hi again, Thanks you're right.

The only case where your fix won't be enough is a very bad classifier f that predicts C for every input. In this scenario, the nearest neighbour will always be from a similar predicted class and method=NG returns a CF within the same class. An idea could be to have a "No CF found" message as it can be the case for method=dtw-barycenter ... ?

Anyway, thanks for your help. Have a nice day !

JHoelli commented 1 year ago

Indeed, that's a really good point. I added a warning that will be available in the next release.

Have a good day.