-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Partial dependence broken in sklearn 1.6.1 when grid has only two values #30938
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
it seems like it is fixed on the main branch. Do you happen to know when will the 1.7 be released? |
We release twice a year, so approximately 6 months after 1.6.0 (around June, I think). |
Will a 1.6.2 get out before then? I could fix that in a separate PR |
We could also backport the fix into 1.6.2 if we can identify which PR is responsible for the fix. I did a quick
For the record, here is the full traceback (including the actual exception type and message) when I run the reproducer on 1.6: Traceback (most recent call last):
File "<python-input-0>", line 10, in <module>
partial_dependence(clf, X=X_test, features=[0], grid_resolution=10, response_method="predict_proba")
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ogrisel/miniforge3/envs/sklearn-1.6/lib/python3.13/site-packages/sklearn/utils/_param_validation.py", line 216, in wrapper
return func(*args, **kwargs)
File "/Users/ogrisel/miniforge3/envs/sklearn-1.6/lib/python3.13/site-packages/sklearn/inspection/_partial_dependence.py", line 682, in partial_dependence
averaged_predictions = averaged_predictions.reshape(
-1, *[val.shape[0] for val in values]
)
ValueError: cannot reshape array of size 1 into shape (2) |
In
I can see that change (and this documentation change) that seems to be it. I did not try it tho. However, this commit does more than just fixing the bug, so i don't know how it should be handled. We could backport only the patch so there will be no (or limited) conflicts later on. |
Hello, do you have an opinion on how things should be handled? |
btw, the bug is also on scikit-learn 1.5.2 For reference: |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
When our input feature has two possible values (and that the grid built in that function hence has two values), partial_dependence will raise an error
ValueError: cannot reshape array of size 1 into shape (2)
What I suspect is happening is that inside
_partial_dependence_brute
function, there is a (wrongful) check to see if there are only two predicted values. This check should not be here because there_get_response_values
seems to do the job of only getting the positive class already.Steps/Code to Reproduce
Expected Results
.
Actual Results
ValueError: cannot reshape array of size 1 into shape (2)
Versions
The text was updated successfully, but these errors were encountered: