Repository navigation
Conversation
_mspline_basis clipped every value at zero. Inside the knot range the scaled B-spline values are non-negative anyway, so the clip acted only on out-of-range rows under an "extrapolate" / "warn" policy, where it cut the negative parts off the extended boundary polynomial pieces and left a kink at the fitted range. The clip now applies only inside the knot range, so the extrapolated M-spline equals the scaled B-spline extension. In-range values and the default clipping policy are unchanged. Fixes #161
This was referenced Nov 29, 2026
This branch has not been deployed
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.
Fixes #161.
With
policy={"out_of_range": "extrapolate"}(or"warn"),MSplineTransformerset every negative basis value to zero. That broke the documented extension on the "extended boundary polynomial pieces of the B/M-spline basis" and left a kink at the fitted range.Root cause
MSplineTransformer._mspline_basis(pretab/expansion/spline/m_spline.py) returnednp.maximum(values * (degree + 1) / knot_span, 0.0). Inside the knot range the B-spline values are already non-negative, so the clip only ever acted on out-of-range rows. There it removed the negative parts of the cubic continuation that the B-spline transformer keeps.Fix
The clip at zero now applies only to values inside the knot range
[t_0, t_last]. Values beyond it keep the scaled B-spline extension,M_k = (p + 1) / (t_{k+p+1} - t_k) * B_k, exactly. The degenerate-support guard and the NaN handling are unchanged.Behaviour changes
"extrapolate"/"warn", out-of-range M-spline rows equal the scaled B-spline extension and can be negative. Before, half of the columns were clipped to zero.ISplineTransformerdoes not use this basis (it is computed in closed form) and is unaffected.Documentation
MSplineTransformerclass docstring: the extrapolated basis is the scaled B-spline extension and can be negative beyond the fitted range._mspline_basisdocstring: non-negative inside the knot range, unclipped outside.docs/representations/spline_expansions.md(M-spline entry): the basis is non-negative inside the range; under"extrapolate"/"warn"it continues the scaled B-spline pieces.BaseSplineTransformer.policyanddocs/representations/choosing_a_method.mdalready describe this behaviour and now hold for M-splines.Tests
tests/core/test_policy.py::test_extrapolated_mspline_rows_are_the_scaled_bspline_extension("extrapolate"/"warn"×include_bias): out-of-range rows equal the scaled B-spline extension, include negative values, are continuous across the boundary, and in-range rows match the default fit. All four cases fail onmainand pass here. The existingtest_extrapolated_mspline_and_tensor_rows_are_not_zeroedstill passes.Reproduction
The script from #161 on this branch:
Checks
just test: 4680 passed, 59 skipped, 7 xfailed; coverage 95.71% (gate 90%).scripts/quickstart.pypasses.just docs: strict build succeeds.just check: all pre-commit and pre-push hooks pass (file hygiene, ruff format, ruff lint, prettier, pyright with 0 errors).pretab.expansion.spline.m_spline; no import direction changes.Merge notes
main. Git merges this branch cleanly with the other open per-issue branches (fix(binning): reject edges the soft encoding cannot use #150 to fix(preprocessor): encode an all-missing categorical batch as object NaN #160).