FIX Ridge.coef_ return a single dimension array when target type is not continuous-multiple#19746
Conversation
…ot continuous-multiple
|
I am unsure which solution would be the good one, because both solutions would be backward incompatible. |
Maybe we could leave the code as it is, just add some documentation about this behavior in the documentation of Ridge and RidgeCV? |
|
I added the following tests: #20604
|
|
@glemaitre @thomasjpfan I've updated the PR, added Guillaume's tests, and added a changelog. This should be good to go. |
| splits = cv.split(X_tiled, y_tiled, groups=indices) | ||
| predictions = cross_val_predict(ridge_reg, X_tiled, y_tiled, cv=splits) | ||
| if predictions.shape != y_tiled.shape: | ||
| predictions = predictions.reshape(y_tiled.shape) |
There was a problem hiding this comment.
It's a bit strange the cross_val_predict does not have the same shape as y[indices].
I'm guessing it's because Ridge.predict will now always return an ndarray of (n_samples,). If Ridge was trained on a y of shape (n_samples, 1), should Ridge.predict return a prediction of shape (n_samples, 1)?
There was a problem hiding this comment.
We have in other places where things fail if the shape is (n_samples, 1). I'm more in favor of having a consistent output shape for single outputs. We probably want cross_val_predict to become more consistent with the rest of the library.
doc/whats_new/upcoming_changes/sklearn.linear_model/19746.fix.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
lorentzenchr
left a comment
There was a problem hiding this comment.
@MaxwellLZH Could you correct the changelog in a tiny new PR?
| @@ -0,0 +1,3 @@ | |||
| - In :class:`linear_model.Ridge` and :class:`linear_model.RidgeCV`, after `fit`, | |||
| the `coef_` attribute is now of shape `(n_samples,)` like other linear models. | |||
There was a problem hiding this comment.
| the `coef_` attribute is now of shape `(n_samples,)` like other linear models. | |
| the `coef_` attribute is now of shape `(n_features,)` like other linear models. |
Reference Issues/PRs
Fixes #19693 following the discussion from @thomasjpfan
Closes #20604
What does this implement/fix? Explain your changes.
Both
Ridge.coef_andRidgeCV.coef_now returns a single dimension array when the result ofsklearn.utils.multiclass.type_of_target(y)is continuous.