Repository navigation
feat: HTML validation report for GLM and multinomial models - #41
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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 formlflow.log_metrics. The docs page isdocs/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
NullOffsetrule 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_pytreated exposure as a weight, which is wrong for rated models. It now takesweights,offsetandlink.diagnostics()raised aTypeErroron a null in a categorical factor. A null is now the levelNone, as in the explorer and the design matrix.For reviewers
test_null_deviance_streaming_matches_naiveandtest_null_deviance_naive_ref_matches_traitcarry a naive reference implementation that reproduced the old behaviour. The reference changes with the fix; no tolerance moved.validation_reportcallsdiagnostics(), so it also writesanalysis/diagnostics.jsonto the working directory.Testing
cargo test --workspace, clippy with-D warningsandcargo fmt --checkpass.mkdocs build --strictpass.🤖 Generated with Claude Code
https://claude.ai/code/session_01FsfCCtS2QSp74cGGxd86Hq