Skip to content

[BUG] set_params silently ignores nested parameters, breaking GridSearchCV #580

Description

@KaranSinghDev

Description

Currently, pyGAM estimators fail to properly route nested parameters. Because set_params() does not recursively handle scikit-learn's double-underscore (__) routing syntax, nested parameters are silently ignored.

This results in a critical silent failure: users running GridSearchCV over a range of term-specific parameters (e.g., varying n_splines) are unknowingly evaluating the exact same default model repeatedly, as the terms never actually update.

Steps to Reproduce

from pygam import LinearGAM, s

gam = LinearGAM(s(0, n_splines=10))

# Scikit-Learn meta-estimators tune nested parameters using this syntax:
gam.set_params(terms__0__n_splines=30)

# The parameter is silently ignored. The term remains unchanged.
assert gam.terms[0].n_splines == 10

So any hyperparameter tuning on specific terms via Pipeline or GridSearchCV is currently a placebo.

I think we can override set_params in GAM to intercept kwargs containing __. Split the key, resolve the target object within the TermList, and apply setattr directly to the nested term.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions