Repository navigation
fix(splines): choose thin-plate landmarks from complete rows - #152
Merged
Merged
Conversation
ThinPlateSplineTransformer declares allow_nan and its transform turns a missing coordinate into a NaN row, but fit passed rows with NaN to the landmark selection: k-means rejected them, and a subsampled NaN landmark made the SVD fail. A tprs feature group with missing_policy="propagate" could therefore not be fitted. fit now selects the landmarks from the rows without a missing value and counts only those rows towards the minimum sample size. Without missing values the landmarks and the basis are unchanged. Add the missing fit and transform docstrings. Fixes #151
This was referenced Nov 29, 2026
mkumar73
approved these changes
Nov 30, 2026
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 #151.
ThinPlateSplineTransformerdeclaresallow_nan=True, and itstransformturns a missing coordinate into a NaN row, butfitfailed on any training row with NaN. Atprsfeature group withmissing_policy="propagate"therefore could not be fitted on data with gaps, althoughdocs/core_concepts/missing_values.mdsays splines propagate missing values.Root cause
fitpassed every validated row, NaN rows included, to_select_landmarks.KMeansrejects NaN, and withlandmark_strategy="subsample"a NaN row could become a landmark, which made the SVD of the projection fail. The landmarks define the whole basis, so they must be complete.Fix
ThinPlateSplineTransformer.fit(pretab/expansion/spline/multivariate/thin_plate.py) selects the landmarks from the rows without a missing value. The minimum-sample check (n_components + n_features + 1) counts those rows; when some rows are incomplete, the error says how many. Without missing values,Xis passed unchanged, so the landmarks, the random draws and the basis are identical tomain.transformis unchanged: a row with a missing coordinate is NaN in every basis column, and a leading bias column stays1.Behaviour changes
fitsucceeds on data with missing values, with either landmark strategy. Before, it raisedValueError(k-means) orLinAlgError(subsample).tprsfeature group withmissing_policy="propagate"fits and returns NaN rows for incomplete rows, liketensorspline.InsufficientSamplesErrorreads e.g.needs at least 8 samples without a missing value (3 of 10 rows have one); got 7.Without missing values, the message is unchanged.Documentation
ThinPlateSplineTransformerdocstring, Notes: how missing values are handled atfitandtransform.fit(withRaises) andtransform, which had none.docs/core_concepts/missing_values.mdalready promises NaN propagation for splines, so the docs now match the behaviour without edits. README, homepage, tutorials anddocs/representations/spline_expansions.mdsay nothing contrary.Tests
tests/expansion/spline/test_thinplate_transformer.py:test_tprs_fits_on_rows_with_missing_values(k-means and subsample; 1, 2 and 3 features): finite landmarks, identical to a fit on the complete rows; NaN rows for incomplete rows. Fails onmain, passes here.test_tprs_missing_rows_keep_the_bias_column: fails onmain, passes here.test_tprs_counts_only_complete_rows_towards_the_minimum_sample_size: fails onmain, passes here.tests/integration/test_feature_groups.py::test_propagated_missing_value_gives_a_nan_group_row(tensorspline,tprs): thetprscase fails onmainand passes here;tensorsplineis a guard that passes on both.Reproduction
The script from #151 on this branch:
23 is the number of rows with a missing value.
Checks
just test: 4686 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.multivariate; no import direction changes.Merge notes
main. Independent of fix(binning): reject edges the soft encoding cannot use #150.