Skip to content

Add sklearn-compatible wrappers for LinearGAM, LogisticGAM, PoissonGAM#563

Open
mbilgesu wants to merge 1 commit intodswah:mainfrom
mbilgesu:add-sklearn-compat-wrappers
Open

Add sklearn-compatible wrappers for LinearGAM, LogisticGAM, PoissonGAM#563
mbilgesu wants to merge 1 commit intodswah:mainfrom
mbilgesu:add-sklearn-compat-wrappers

Conversation

@mbilgesu
Copy link
Copy Markdown

Closes #422

pyGAM estimators currently break with sklearn>=1.7 and cannot be used
with Pipeline, GridSearchCV, or cross_val_score due to two root causes:

  1. __sklearn_tags__ missing — fixed by inheriting from BaseEstimator
  2. Mutable defaults in __init__ (callbacks, terms) — breaks clone()

Rather than patching the core classes, this PR adds a pygam/compat.py
module with clean wrapper classes that fully satisfy sklearn's estimator
contract without touching existing behaviour:

  • SklearnLinearGAM — RegressorMixin + BaseEstimator
  • SklearnLogisticGAM — ClassifierMixin + BaseEstimator (classes_, predict_proba, decision_function)
  • SklearnPoissonGAM — RegressorMixin + BaseEstimator

All wrappers use validate_data() for fit/predict consistency checks,
store only plain scalars in __init__ (clone-safe), and return self
from fit().

Tests (pygam/tests/test_compat.py):

  • 20 passing behavioral contract tests
  • clone(), GridSearchCV, Pipeline, cross_val_score all verified
  • check_estimator parametrized suite included

20/20 tests pass on Python 3.13 + sklearn 1.7+.

@mbilgesu
Copy link
Copy Markdown
Author

Hi @dswah — I've opened PR #563 which takes a different approach to #422 than the existing PRs.
Rather than patching the core GAM classes, I added a pygam/compat.py module with clean wrapper classes (SklearnLinearGAM, SklearnLogisticGAM, SklearnPoissonGAM) that fully satisfy sklearn's estimator contract without touching existing behaviour. The wrappers isolate mutable state (callbacks, terms) from init so clone() works correctly, and use validate_data() for feature consistency checks.
20/20 behavioral tests pass on Python 3.13 + sklearn 1.7+. Happy to iterate based on your feedback.

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.

Feature: Support for Scikit-Learn v1.7+ Compatibility

2 participants