Skip to content

fix(splines): do not report explicit knot placement as target-aware - #186

Open
ChrisW09 wants to merge 2 commits into
mainfrom
fix/185-explicit-knots-target-usage
Open

ChrisW09 wants to merge 2 commits into
mainfrom
fix/185-explicit-knots-target-usage

Conversation

@ChrisW09

@ChrisW09 ChrisW09 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #185.

With explicit knot_locations and target_aware=True, BSplineTransformer, MSplineTransformer and ISplineTransformer emitted a LeakageWarning and reported uses_target_ == True, and get_representation_spec().uses_target was True as well, although no selector reads y on that path.

Root cause

RepresentationSpecMixin.is_supervised (pretab/core/representation.py) returns requires_y or target_aware. uses_target_, the spec flag and warn_target_leakage all read it. BaseSplineTransformer.fit skips the target-aware selector when knot_locations is set, but nothing told the mixin.

Fix

BaseSplineTransformer overrides is_supervised (pretab/expansion/spline/base.py): bool(self.target_aware) and self.knot_locations is None. The leakage warning, uses_target_ and RepresentationSpec.uses_target follow it. The knot placement itself is unchanged.

Behaviour changes

  • B/M/I splines with explicit knot_locations emit no LeakageWarning and report uses_target_ == False and spec.uses_target == False, whatever target_aware is.
  • Target-aware B/M/I splines without knot_locations are unchanged: they still warn and report True.
  • knot_locations is a standalone-transformer option that Preprocessor does not accept, so preprocessor lineage is unaffected.

Not included

A fitted transformer whose target_aware is changed with set_params but not refit still derives the flag from the current parameter. Recording target use at fit time would add fitted state, change fingerprints and touch every family, so it is left for a separate issue.

Documentation

  • BaseSplineTransformer docstring (knot_locations) and the new is_supervised docstring.
  • docs/core_concepts/target_awareness.md ("The fitted-usage flag"): a B/M/I spline with explicit knot_locations reports False and emits no LeakageWarning, even with target_aware=True.

Tests

In tests/core/test_supervised_contract.py:

  • test_explicit_knot_locations_are_not_target_aware (B, M and I splines): no LeakageWarning (escalated to an error), uses_target_ and spec.uses_target are False, and the output is independent of y. Fails on main, passes here.
  • test_target_aware_spline_without_knots_stays_supervised: guard that passes on both.

Reproduction

The script from #185 on this branch:

output identical for unrelated targets: True
warnings: []
uses_target_: False | spec.uses_target: False

Checks

  • just test: 4680 passed, 59 skipped, 7 xfailed; coverage 95.71% (gate 90%).
  • Minimum dependencies (CI job: Python 3.11, numpy 1.24.4, pandas 2.0.3, scipy 1.10.1, scikit-learn 1.6.0): 4497 passed, 173 skipped, 7 xfailed; scripts/quickstart.py passes.
  • 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).
  • The change stays inside pretab.expansion.spline.base; no import direction changes.

Merge notes

Explicit knot_locations take priority over target-aware placement, so
no selector reads y. With target_aware=True the B/M/I splines still
emitted a LeakageWarning and reported uses_target_ / spec.uses_target as
True, because target use was derived from target_aware alone.

BaseSplineTransformer.is_supervised now returns True only for
target-aware placement without knot_locations; the leakage warning,
uses_target_ and the representation spec follow it.

Fixes #185
Move the sentence out of the paragraph on ignored targets, which #176
also extends, so the two branches merge without a conflict.

Refs #185

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

B/M/I splines with explicit knot_locations warn about leakage and report uses_target_=True although y is never read

1 participant