Repository navigation
Responses separate from ModelSpec; wildcard(exclude=) takes a response - #3
Merged
Merged
Conversation
As in scikit-learn, the design and the response are built separately:
ModelSpec no longer has a `response` parameter or `build_response`.
- Surv, Binomial and Multinomial are fit and built on their own:
`fit`, `transform`, `fit_transform`, in the backend of the data
(e.g. polars, with an Enum for a categorical).
- `wildcard(exclude=...)` also takes a Response, leaving out its
columns: `ModelSpec([wildcard(exclude=Surv('time', 'status'))])`.
- build_submodel expands a wildcard as at fit.
- Poly, BSpline and NaturalSpline are fit on the observed values and
are missing only in the rows where the variable is missing, as
scikit-learn's transformers: a single NaN made the whole feature
NaN (and, for ns, uninitialized values could leak through).
- The conversion of dataframes of other backends moves to _native.py.
- Docs: the responses page rewritten for this, and a section on
missing values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follows #2, which was merged before this commit was pushed. As in scikit-learn, the design and the response are built separately: a
ModelSpecbuildsX, and a response object buildsyfrom the same data.Responses separate from
ModelSpec.ModelSpecloses itsresponse=parameter andbuild_response; neither has been released, so nothing breaks.Surv,BinomialandMultinomialare fit and built on their own withfit,transformorfit_transform. A dataframe of another backend, such as polars, gives a response in that backend (for polars, a categorical comes back as an Enum).wildcard(exclude=...)takes a response and leaves out its columns, so the response is named once and cannot leak into its own design:MS([wildcard(exclude='y')])is the design of R'sy ~ .. A barewildcardis every column.build_submodelexpands a wildcard as at fit.Missing values, following scikit-learn: transformers keep every row, fit on the observed values, and are missing where their input is. This fixes a bug where a single NaN made every value of a
poly,nsorbsfeature NaN (andnscould return uninitialized values). The docs show how to choose the rows R'sna.omitkeeps.The conversion of dataframes of other backends moves to
modelmatrix/_native.py, soresponse.pycan use it.Tests: 265 passed and 5 strict xfails. New tests cover missing values in
poly,nsandbs; responses returned in polars and pyarrow; andexclude=given a response.Docs: the responses page is rewritten for this design and executes locally.
Sales ~ .still gives R'slmcoefficients, and dropping incomplete rows ofHittersleaves R's 263.🤖 Generated with Claude Code