Skip to content

feat: HTML validation report for GLM and multinomial models - #41

Merged
PricingFrontier merged 8 commits into
mainfrom
feat/html-validation-report
Nov 9, 2026
Merged

PricingFrontier merged 8 commits into
mainfrom
feat/html-validation-report

Conversation

@PricingFrontier

Copy link
Copy Markdown
Owner

Summary

Adds a self-contained HTML validation report for fitted GLMs and multinomial models, in the theme of the t-boost report, and fixes three existing library bugs found while building it.

html = result.html_report(train, test_data=test, name="Motor frequency v3")

report = result.validation_report(train, test_data=test)  # JSON-safe, to keep beside the model
html = rs.report_html(report)                             # draws a saved report

The page has no scripts and loads nothing from the network, so it works offline and where scripts are blocked. Tabs: Overview, Performance, Factors, Interactions, Coefficients, Fit, Checks. report["summary_metrics"] is flat and valid for mlflow.log_metrics. The docs page is docs/api/validation-report.md.

Multinomial models get the same page with a class switch. Each class is reviewed one-vs-rest with the same charts and checks, alongside whole-model deviance, accuracy, confusion and expected-count matrices, and the class mix.

Review flags need both a tolerance and a z-score, so small bands do not raise noise. Deciles, factor bands, interaction cells and overall A/E follow the same rule.

Fixes that change existing numbers

  • Null deviance with an offset. The null model decided how to use an offset from the family's default link, so a Gaussian fit ignored its offset, despite a docstring promising otherwise. One NullOffset rule now reads the fitted link on every fit path, in memory and out of core, with the constant that is optimal for the family's variance function. Null deviance, deviance explained and the likelihood-ratio test change for Gaussian, Gamma and Tweedie fits with an offset, and for any fit whose link is not its family's default. These now match statsmodels. Fits with no offset and Poisson-type log-link fits do not change.
  • compute_null_deviance_py treated exposure as a weight, which is wrong for rated models. It now takes weights, offset and link.
  • Continuous factor bands were rounded to four decimals, which collapsed factors on a small scale. Bands keep their true edges; JSON output still rounds.
  • diagnostics() raised a TypeError on a null in a categorical factor. A null is now the level None, as in the explorer and the design matrix.

For reviewers

  • test_null_deviance_streaming_matches_naive and test_null_deviance_naive_ref_matches_trait carry a naive reference implementation that reproduced the old behaviour. The reference changes with the fix; no tolerance moved.
  • Negative binomial and logit fits with an offset keep their existing null constant. No closed form exists and a single-pass fit cannot iterate for one.
  • validation_report calls diagnostics(), so it also writes analysis/diagnostics.json to the working directory.
  • Per-row work in the report uses vectorised numpy on existing kernels, as the diagnostics module does; there is no new Rust kernel.

Testing

  • cargo test --workspace, clippy with -D warnings and cargo fmt --check pass.
  • Python suite and the 97% coverage gate pass; ruff, the policy checks and mkdocs build --strict pass.
  • New tests cover seven GLM families, multinomial, weights, offsets, exposure, complements, loaded, regularised, smooth and out-of-core fits, and hostile column names. Null deviance is checked against statsmodels for Gaussian, Gamma and Tweedie.
  • Pages were checked in headless Chromium with JavaScript disabled, in light and dark, at desktop and phone widths.
  • Reviewed with Codex (gpt-6-astra, read-only) in two rounds. All findings are fixed with regression tests, apart from the negative binomial limit above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq

PricingFrontier and others added 8 commits November 9, 2026 22:26
The null model decided how to use an offset from the family's default link,
so an identity-link fit ignored its offset, although the docstring promised
mean(y - offset) + offset. One NullOffset rule, read from the fitted link,
now serves every fit path, in memory and out of core. A Gaussian fit with an
offset matches statsmodels.

compute_null_deviance_py passed exposure as a weight, which is wrong for a
rated model. It now takes weights, offset (on the linear-predictor scale) and
link, and accepts every family through the shared family parser.

The naive reference in the model_fit tests reproduced the old identity-link
behaviour, so it changes with the fix; no tolerance moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
A null in a categorical factor reached pl.Enum as a category and raised a
TypeError. It is now the level "None", as in the explorer, pair diagnostics
and the design matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
result.html_report(train, test_data=test) returns one self-contained page
for reviewing a fitted model, in the theme of the t-boost report. It has no
scripts and loads nothing from the network. validation_report returns the
same content as a JSON-safe dictionary; rs.report_html draws a saved one.

Tabs cover performance in and out of sample, each factor's fitted effect with
a confidence band and its A/E, interactions, coefficients, residual and
variance checks, influence, and review flags with their thresholds. Flags need
both a tolerance and a z-score, so small bands do not raise noise.

A multinomial model is reviewed one-vs-rest per class with a class switch,
beside its deviance, accuracy, class matrices and class mix. Each class view
has the shape of a GLM report, so both share one set of charts and checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
Review of the link-aware null model found that the log-link constant used
the Poisson formula for every family, which is only optimal for V(mu) = mu.
It is now c = sum(w y a^(1-p)) / sum(w a^(2-p)) with p the family's variance
power, so Gaussian, Gamma and Tweedie fits with an offset match statsmodels.
Poisson-type fits are unchanged.

A fit that skipped its covariance recomputed the null deviance with the
family's default link. The result now keeps the fitted link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
- Compare multinomial deviances on the rows and weights the report was given.
- Render smooth terms that report no test.
- Build the null model from the offset prediction uses, complement included.
- Keep continuous bands at their true edges, not four decimal places.
- Treat tied predictions as one Lorenz segment, so row order cannot move Gini.
- Count levels the train data did not have in PSI.
- Draw fitted-value charts when a holdout has fewer rows than bands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
- Apply an array complement to the train rows' null model.
- Pass an exposure override and transformed exposure through to the complement.
- Compute the GLM Gini with tied predictions as one segment, as the Lorenz curve is.

Negative binomial and logit fits with an offset keep their closed-form null
constant: no exact one exists and a single-pass fit cannot iterate for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
A newer local uv rewrote environment markers across the lockfile. No dependency
changed, so keep the bump to rustystats' own version line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq
@PricingFrontier
PricingFrontier merged commit 873592b into main Nov 9, 2026
17 checks passed
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