Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

490 implement lime for timeseries #527

Merged
merged 27 commits into from
Apr 16, 2023
Merged

Conversation

geek-yang
Copy link
Member

@geek-yang geek-yang commented Mar 20, 2023

In this PR, we implement LIME for timeseries based on Lime-for-time and LimeSegmentation, which are described in this paper https://doi.org/10.1016/j.jocs.2021.101539.

To make use of the maskers generator, this PR already includes the working progress in PR #494 (which is related to issue #477).

This PR closes issue #490.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@geek-yang
Copy link
Member Author

geek-yang commented Mar 20, 2023

Note that since the general explainer function for timeseries have already been implemented in PR #506

def explain_timeseries(model_or_function, timeseries_data, method, labels, **kwargs):
"""
Explain timeseries data given a model and a chosen method.
Args:
model_or_function (callable or str): The function that runs the model to be explained _or_
the path to a ONNX model on disk.
input_data (np.ndarray): Image data to be explained
method (string): One of the supported methods: RISE, LIME or KernelSHAP
labels (Iterable(int)): Labels to be explained
Returns:
One heatmap per class.
"""
explainer = _get_explainer(method, kwargs, modality="Timeseries")
explain_image_kwargs = utils.get_kwargs_applicable_to_function(explainer.explain, kwargs)
return explainer.explain(model_or_function,
timeseries_data,
labels,
**explain_image_kwargs)
please don't re-implement that in this PR.

@geek-yang geek-yang linked an issue Mar 20, 2023 that may be closed by this pull request
@cpranav93
Copy link
Contributor

@geek-yang, Lime for time-series is working now in Dianna! Can you have a look? We can have a discussion about the format of the class maybe after you do.

@geek-yang
Copy link
Member Author

@geek-yang, Lime for time-series is working now in Dianna! Can you have a look? We can have a discussion about the format of the class maybe after you do.

Hi @cpranav93, good job! I tested it and it works very well with the coffee dataset. Follow our discussion, I made some changes and now it supports the api interface of dianna, which also works with onnx when you wrap it up as a model runner.

But when I try to test it with weather dataset, it doesn't work. I tried to make some changes to it but still didn't get any sensible result (you can find my test in the notebook lime_timeseries_weather.ipynb) . Since this PR is already super large, I suggest we wrap it up like this and continue our work in another PR.

@geek-yang geek-yang marked this pull request as ready for review April 13, 2023 14:32
@geek-yang
Copy link
Member Author

Finally this big PR (about 1800 lines of code added) is ready for review. Note that this is the first step towards our own implementation of LIME for timeseries data and more need to be achieved to make it better. But now it already functions in a way that we can further polish it to improve the results from the explainer (and most importantly, it is integrated with our dianna api and you can run all notebooks without an error 😜).

In the code you will find many TODO things, which are listed below with a dedicated issue made for each of them:

Also, some results from the notebooks are not good enough, and they are expected to be improved when we fix issues related to the algorithm of LIME (due to the use of lime_base module) and implement smart segmentation strategy and masking for multiple channels. A new issue link to this is created as well for the improvement of the tutorial notebooks:

Please for now just ignore these TODOs when you review this PR.

@cpranav93
Copy link
Contributor

Great work @geek-yang! It really looks great now. The new issues you created will also be very helpful in improving our implementation of lime as well! Go ahead and merge.

@geek-yang geek-yang merged commit e69213b into main Apr 16, 2023
@geek-yang geek-yang deleted the 490-implement-lime-for-timeseries branch April 16, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Self implement lime methodology for time-series
2 participants