-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
GridSearchCV fails when parameters are arrays with different sizes #29277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Workaround: looking at the source code reveals a temporary fix - to turn the arrays into nested lists. Doing this signals to sklearn that these parameters should be treated as objects and not forced into one array. In the code example provided, changing lines 29-30 from 'splinetransformer__knots' : [np.linspace(0,np.pi*2,n_knots).reshape((-1,1))
for n_knots in range(10,21,5)], to 'splinetransformer__knots' : [np.linspace(0,np.pi*2,n_knots).reshape((-1,1)).tolist()
for n_knots in range(10,21,5)], solves the issue. Perhaps this treatment should be extended to cover not only when parameters are clearly objects (when they are lists/tuples), but also whenever putting them into an array fails for whatever reason - as that failure can be interpreted as indication that they should be treated as objects. |
Thanks for the report @Gabriel-Kissin. It looks like another side effect of #28352. Ping @MarcoGorelli for confirmation, and maybe propose a quick fix ? |
oh no, not another one i'll take a look, thanks for the ping |
I just tried this out on Looks like it's already fixed, and all that's needed is another release |
Hum that's weird cause I'm able to reproduce the error on main, same commit :/ |
that's probably cause I don't practice building sklearn often enough, just went through the setup instructions again and can reproduce π³ taking a look now π |
fix incoming |
Describe the bug
SplineTransformer
accepts arrays for theknots
argument to specify the positions of the knots.Using
GridSearchCV
to find the best positions fails if theknots
array has a different size (i.e. if there is a differentn_knots
). This appears to be because the code attempts to coerce the parameters into one array, and therefore fails due to the inhomogeneous shape.Note: sklearn versions - this error only occurs in recent versions of sklearn (1.5.0). Earlier versions (1.4.2) did not suffer from this issue.
Note 2: the issue would be avoided if the
n_knots
parameter were to be searched over (instead of theknots
parameter). However, it is often important to specify the knots positions directly - for example, with periodic data, as in the provided example, as the periodicity is defined by the first and last knots. In any case there are presumably other places in sklearn where arrays of different shapes can be provided as parameters and where the same issue will occur.Steps/Code to Reproduce
Expected Results
This is sample output from earlier versions of sklearn:

Actual Results
Error:
Full traceback:
Versions
The text was updated successfully, but these errors were encountered: