Skip to content

Add per-timestep TFT variable importance plot - #3174

Open
exactml wants to merge 7 commits into
unit8co:masterfrom
exactml:feat/tft-explainer-plot-importance-over-time
Open

Add per-timestep TFT variable importance plot#3174
exactml wants to merge 7 commits into
unit8co:masterfrom
exactml:feat/tft-explainer-plot-importance-over-time

Conversation

@exactml

@exactml exactml commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Checklist before merging this PR:

  • Mentioned all issues that this PR fixes or addresses.
  • Summarized the updates of this PR under Summary.
  • Added an entry under Unreleased in the Changelog.

Addresses #2685.

Summary

Adds the plotting follow-up to #3170 (which added the per-timestep data layer but intentionally left visualization out of scope).

  • New TFTExplainer.plot_variable_selection_over_time() plots the encoder/decoder variable importances from get_encoder_importance_over_time() / get_decoder_importance_over_time() as two line-chart subplots (one line per variable), instead of the stacked-bar approach originally prototyped in the issue thread.
  • show_index_as: Literal["relative", "time"] = "relative" mirrors the existing plot_attention() convention. "relative" re-indexes both series around the first prediction point (0); "time" uses the real dates the importances were already computed against, unchanged.
  • max_nr_components caps how many variable lines are drawn per subplot, reusing the same knob TimeSeries.plot() already exposes — addresses the "unreadable past ~20 features" issue @MichaelVerdegaal raised in the thread.
  • Line plots (rather than stacked bars) were chosen specifically to avoid the dense/overlapping x-axis labels that stacked bars hit on long input_chunk_length series — verified TimeSeries.plot()'s existing date-axis handling already degrades gracefully on long date ranges.
  • Left out of v1, per discussion: auto-merging cyclic sin/cos encoder pairs (a darts-encoder-specific naming heuristic, better left to the user), and "normalize by attention" (the original prototyper's own retrospective found it didn't pull its weight).

Other Information

Testing:

  • Added test_variable_selection_over_time_plotting in test_tft_explainer.py, covering both n_series cases: subplot titles/count, per-variable line count, max_nr_components capping, and the show_index_as validation error.
  • pytest darts/tests/explainability/test_tft_explainer.py — 54 passed.

exactml added 3 commits August 1, 2026 15:05
Visualizes the per-timestep encoder/decoder variable importances
exposed via get_encoder_importance_over_time()/get_decoder_importance_over_time(),
following up on unit8co#2685. Mirrors plot_attention()'s show_index_as
convention and reuses TimeSeries.plot()'s max_nr_components cap and
date-axis handling instead of a hand-rolled stacked-bar chart.
Covers subplot titles/count, per-variable line count, max_nr_components
capping, and the show_index_as validation error.
PR number is a placeholder (#XXXX) until the PR against unit8co/darts
is actually opened.
@exactml
exactml requested a review from dennisbader as a code owner August 1, 2026 12:06
exactml added 4 commits August 1, 2026 15:08
Uses a 60/20-timestep daily input/output chunk length with 36/18
encoder/decoder variables (>20, marked slow) to confirm the default
max_nr_components cap and TimeSeries.plot()'s date-axis handling keep
the plot readable at realistic scale, not just on the small fixtures
used elsewhere in this file.
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.97%. Comparing base (080b534) to head (d8fbbf6).

Files with missing lines Patch % Lines
darts/explainability/tft_explainer.py 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3174      +/-   ##
==========================================
- Coverage   97.03%   96.97%   -0.06%     
==========================================
  Files         165      165              
  Lines       17951    17982      +31     
==========================================
+ Hits        17418    17438      +20     
- Misses        533      544      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@exactml

exactml commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@dennisbader can you review it when you available?

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.

1 participant