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

Function for visualising time series attribution #958

Closed
smaeland opened this issue May 27, 2022 · 5 comments
Closed

Function for visualising time series attribution #958

smaeland opened this issue May 27, 2022 · 5 comments

Comments

@smaeland
Copy link
Contributor

🚀 Feature

Function for visualising time series along with attribution values, just like captum.attr.visualization.visualize_image_attr does for images.

Motivation

Working with time series a lot, I often copy the same plotting function around between projects, so I think it would be great to have a basic 1D plotting method built-in. Since 1D attributions are prepared the same way as for images (normalisation and choice of sign), it would fit in nicely with the existing code. I would be happy to submit a PR with my own (adapted) plotting function, but probably best to first discuss the scope and need.

Pitch

A built-in plotting function would simplify and speed up the model development cycle. But besides convenience, it could also be valuable to new users, since the applicability of Captum to time series is somewhat undercommunicated 😄

Alternatives

Users write their own custom plotting functions. This is likely to happen anyway because of the big variation in different time series' length, number of channels, etc., but in that case, a built-in function is a good starting point.

Additional context

@NarineK
Copy link
Contributor

NarineK commented Jun 9, 2022

@smaeland, thank you for proposing this functionality. Sure, feel free to send a PR.
cc: i-jones

facebook-github-bot pushed a commit that referenced this issue Jul 5, 2022
Summary:
Add a convenience function to plot time series data with attributions overlaid (`captum.attr.visualization.visualize_timeseries_attr`). This addresses #958 .
Comes with three styles, shown here for some dummy data:

1) Plot each channel in a separate panel, with separate heatmaps overlaid
![overlaid_individual](https://user-images.githubusercontent.com/30171842/174852816-f3c7d67f-d03f-4d04-91b4-6766052a640d.png)

2) Plot all channels in a single panel, with average heatmap overlaid
![overlaid_combined](https://user-images.githubusercontent.com/30171842/174852821-1ab089b2-9e30-4233-9726-dd3e3d9f03f5.png)

3) Plot each channel in a separate panel and color the graphs by attribution values at each time step
![colored_graph](https://user-images.githubusercontent.com/30171842/174852820-f0be8148-d432-43f3-a301-e783b98dece0.png)

The function accepts matplotlib keyword arguments for additional styling.

Pull Request resolved: #980

Reviewed By: vivekmig

Differential Revision: D37495470

Pulled By: i-jones

fbshipit-source-id: d218dc035d7158af39480a4df63a0bb9500f495c
@ic085908
Copy link

ic085908 commented Jul 7, 2022

@smaeland Thank you for your helpful function for plotting time series.
I tried to learn explainable method for time series and used your function for visualization. However, I am struggling with these processes of transferring my model to explainable method and visualization .
Could you give a simply example to use your function of time series? I apologize for this may disturb you, I am a green hand.

In any case, thanks for your help.

@smaeland
Copy link
Contributor Author

smaeland commented Jul 9, 2022

Hi @ic085908, here is the script I used to produce the plots shown in #980: visualize_synthetic_data.py (data is randomly generated, so it won't look exactly identical). Let me know if you run into any problems or find things that could be improved

@ic085908
Copy link

ic085908 commented Jul 9, 2022

Hello @smaeland, I really appreciate your help.
The script smoothly runs as a figure below. I will apply your script to my model.
image
Many thanks,

@smaeland
Copy link
Contributor Author

smaeland commented Jul 9, 2022

Great! I'll close this then, since the corresponding PR is merged now.

@smaeland smaeland closed this as completed Jul 9, 2022
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

No branches or pull requests

3 participants