Skip to content

feat(plots): operational diagnostics plots#215

Merged
bartzbeielstein merged 2 commits into
developfrom
feat/diagnostics-plots
Jun 12, 2026
Merged

feat(plots): operational diagnostics plots#215
bartzbeielstein merged 2 commits into
developfrom
feat/diagnostics-plots

Conversation

@bartzbeielstein

Copy link
Copy Markdown
Collaborator

Upstreams the team4 diagnostic figures as a new plots.diagnostics module: feature_family, plot_acf_with_lags, plot_feature_importance_by_family, plot_shap_summary, plot_forecast_vs_reference (generalized forecast-vs-ENTSO-E plot; tolerates empty reference overlap). All return Figure, caller owns saving/closing. Reviewed (MAD-unit-scaling blocker + 4 findings resolved; feature_family kept out of the package-root namespace). Full pipeline green incl. quarto render.

🤖 Generated with Claude Code

bartzbeielstein and others added 2 commits June 12, 2026 02:49
…, SHAP summary, forecast-vs-reference)

Ports five matplotlib helpers from bart26k-lecture/scripts/team4_4zones_submit.py
into a reusable, stateless public API in spotforecast2.plots.diagnostics:

- feature_family(name) — maps LGBMRegressor feature names to six diagnostic families
- plot_acf_with_lags(acf, key_lags, conf) — bar chart with confidence band and annotated key lags
- plot_feature_importance_by_family(names, importances, top_n) — top-N barh coloured by family
- plot_shap_summary(estimator, X, max_samples) — subsampled TreeExplainer bar summary
- plot_forecast_vs_reference(forecast, reference, ...) — generalised forecast-vs-ENTSO-E line plot

All functions return matplotlib.figure.Figure; the caller saves/closes.
No plt.show(), no matplotlib.use(), no global state mutation.
Overlap MAD is logged at INFO via the module logger (preserved from the original).
44 new tests in tests/test_plots_diagnostics.py; 1207 tests pass total.
Registered in _quarto.yml sidebar + quartodoc contents (plots.diagnostics).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
FIX 1 (blocker): plot_forecast_vs_reference MAD log now uses
`mad * unit_scale` (not `mad / unit_scale`) so the value is
reported in the display unit (GW) rather than inflated by 1000×.
Log format updated to include the unit label. Strengthened test
asserts logged value is 1.0 GW for a constant 1000 MW offset.

FIX 2: plot_shap_summary docstring notes the figure is harvested
via plt.gcf() (shap API limitation), the function is not
thread-safe, and callers must close the returned figure before
other pyplot work.

FIX 3: plot_shap_summary docstring replaces "at most max_samples
rows" with the precise stride description.

FIX 4: Remove feature_family from plots/__init__.py re-exports
and __all__; it is a string classifier, not a plot function.
Remains public at spotforecast2.plots.diagnostics.feature_family.
Tests already used the full module path — no changes needed there.

FIX 5: Remove dead n_annotated variable in plot_acf_with_lags.

FIX 6: Remove per-example matplotlib.use("Agg") calls from the
four docstring Examples; examples still avoid plt.show().

FIX 7: Add two feature_family precedence cases to the parametrized
table: "poly_window_24" -> "polynomial" and "sin_window" ->
"weather_window", pinning holiday > poly > window > cyclical > lag.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bartzbeielstein bartzbeielstein merged commit af103ab into develop Jun 12, 2026
9 checks passed
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@bartzbeielstein

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 8.1.0-rc.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@bartzbeielstein

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 8.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@bartzbeielstein bartzbeielstein deleted the feat/diagnostics-plots branch June 12, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant