feat: parity with R moderndive PR #144 (glm, multi-cor, 3D, View)#14
Merged
Conversation
Bring the Python port up to the R moderndive master (PR #144 "Resolving outstanding issues"): - get_correlation(): multiple RHS predictors -> long output by default, wide=True for one column per predictor; suppressible (quiet=True) note about a full pairwise matrix. Single-predictor behavior unchanged. - get_regression_table/points/summaries(): accept fitted glm() models. GLM points are on the response scale (e.g. probabilities); summaries are glm-shaped (deviance, null_deviance, aic, bic, log_lik, df_residual, df_null, nobs); get_regression_table() gains exponentiate= for odds/rate ratios. - get_regression_points(): in-formula transformation handling — transformed outcome (np.log(mpg) -> log_mpg/log_mpg_hat) shown on the model scale, and transformed predictors (poly/scale/I) shown as their original columns rather than leaking basis matrices. Now requires a formula-API model (clear error). - plot_3d_regression(data, "z ~ x + y"): interactive 3D scatter + fitted plane (plotly), with validation and beginner-friendly errors. - View(): interactive searchable table via the optional itables package (Python counterpart of R DT::datatable), graceful fallback without it. New optional `view` extra. - geom_categorical_model() alias of gg_categorical_model() (already present). - New moderndive/_messaging.py: infer-style messages/errors (summary + → hints); informational notes use a suppressible ModernDiveMessage warning category, used across the new code. Docs: API reference, regression guide (multi-cor, glm, 3D), getting-started (View) updated; CHANGELOG. Tests: new tests/test_pr144_parity.py covering all five features + edge cases + messaging. 241 tests, 100% coverage, ruff clean, docs build warning-free under -W. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
- get_regression_table/points/summaries() now also accept array-API fits (sm.OLS(y, X).fit() / sm.GLM(...)), not just the formula API. Term names fall back to exog_names when params is a bare numpy array; points are built from the endog/exog arrays (constant column dropped), with the same GLM response-scale handling. Formula-API transform handling is unchanged. - New docs guide guides/messages.md: shows the beginner-friendly, infer-style messages/errors (summary + → hints) with executed output, and how to silence the informational ModernDiveMessage notes (quiet= / warnings filter). - Tests cover numpy + pandas array-API OLS and GLM paths. 242 tests, 100% coverage, ruff clean, docs build warning-free under -W. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
CI installs only the test extra (no itables), so the View render-path tests took the fallback branch and failed. Force _itables_available() in those tests and add a direct test of the real detector, so the suite passes (and stays at 100% coverage) whether or not the optional itables dependency is present. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017CTL1QSTg1DmDUpqYuPEog
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.
Brings the Python port up to R
moderndivemaster, matching moderndive/moderndive#144 ("Resolving outstanding issues"). Implements all five gaps identified vs. that PR.What's new
get_correlation()— multiple predictors."y ~ x1 + x2 + x3"returns one correlation per predictor (long by default;wide=Truefor one column each). A suppressible note (quiet=True) points to a full pairwise matrix. Single-predictor behavior is unchanged.glm()support inget_regression_table/points/summaries. GLMpointsare on the response scale (e.g. probabilities for logistic);summariesare GLM-shaped (deviance,null_deviance,aic,bic,log_lik,df_residual,df_null,nobs);get_regression_table()gainsexponentiate=for odds/rate ratios.get_regression_points(). A transformed outcome (np.log(mpg)) is shown on the model scale aslog_mpg/log_mpg_hat; transformed predictors (poly(),scale(),I()) show their original columns instead of leaking basis matrices.plot_3d_regression(data, "z ~ x + y")— interactive 3D scatter with a fitted regression plane (plotly), with validation + friendly errors.View()— interactive, searchable table via the optionalitablespackage (the Python counterpart of R'sDT::datatable()), with a graceful fallback when itables isn't installed. New optionalviewextra.Plus:
geom_categorical_model()alias confirmed, and a newmoderndive/_messaging.pygiving beginner-friendly,infer-style messages/errors (a summary line +→hint bullets); informational notes use a suppressibleModernDiveMessagecategory and are used throughout the new code.Quality
tests/test_pr144_parity.pycovers all five features + edge cases (errors, pandas input, transformed LHS/RHS, GLM response-scale residuals, exponentiate, quiet/wide, View fallback) and the messaging helpers.-W(15 rendered plots incl. the new 3D one).Notes
plotlyis already a core dep, soplot_3d_regressionneeds nothing extra.itablesis optional (pip install "moderndive[view]") to keep the core light and Pyodide-friendly; also added to thedocextra so the docs can showView().🤖 Generated with Claude Code