Skip to content

Test for sklearn compatibility with default parameters#991

Draft
Jan Tilly (jtilly) wants to merge 4 commits intomainfrom
check-estimator
Draft

Test for sklearn compatibility with default parameters#991
Jan Tilly (jtilly) wants to merge 4 commits intomainfrom
check-estimator

Conversation

@jtilly
Copy link
Copy Markdown
Member

check_estimator was previously only run with non-default parameters (alpha=1.0 / n_alphas=2), hiding failures that occur with the default constructor. Add a parametrized test that calls check_estimator() with no arguments so CI will catch regressions against sklearn's API.

Checklist

  • Added a CHANGELOG.rst entry

Jan Tilly (jtilly) and others added 4 commits March 25, 2026 09:03
When alpha=0 (no L2 penalty), the closed-form solver previously built
normal equations (H = X'WX) and solved them with scipy.linalg.solve.
Forming normal equations squares the condition number; for
underdetermined systems this caused scipy to return an inaccurate result
that differed depending on whether sample weights were supplied as
explicit weights or as repeated rows – violating sklearn's
check_sample_weight_equivalence contract.

Fix: when P2 = 0, solve the equivalent WLS problem directly via lstsq on
the sqrt-weighted data matrix (sqrt(W)·X, sqrt(W)·y). This matches the
approach used by sklearn.linear_model.LinearRegression, avoids squaring
the condition number, and gives a unique minimum-norm solution that is
consistent across the two representations. When P2 != 0 the L2 penalty
already makes the normal equations well-conditioned, so that path is
retained unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant