Skip to content
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

Fix LogisticRegression.decision_function output shape #6235

Open
wants to merge 1 commit into
base: branch-25.04
Choose a base branch
from

Conversation

jcrist
Copy link
Member

@jcrist jcrist commented Jan 17, 2025

Previously this would return (n_classes, n_rows) for multiclass, whereas sklearn returns (n_rows, n_classes).

Fixes #5741.

@jcrist jcrist requested a review from a team as a code owner January 17, 2025 22:43
@jcrist jcrist requested review from teju85 and divyegala January 17, 2025 22:43
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Jan 17, 2025
@jcrist jcrist added bug Something isn't working non-breaking Non-breaking change and removed Cython / Python Cython or Python issue labels Jan 17, 2025
@jcrist
Copy link
Member Author

jcrist commented Jan 17, 2025

Labeled this as "non-breaking", since the old behavior was a bug and unexpected. This is a behavior change though, so in the off chance that someone's relying on it then it would be a breaking change.

@@ -717,8 +717,6 @@ def test_logistic_regression_decision_function(
sklog.classes_ = np.arange(num_classes)

cu_dec_func = culog.decision_function(X_test)
if cu_dec_func.shape[0] > 2: # num_classes
cu_dec_func = cu_dec_func.T
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a heck of a long shot, but @divyegala, do you recall why we did this to begin with? It seems like such a deliberate decision that I want to make sure we're not missing something. Also fine with just merging if no one remembers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is still required. This is a hypothesis-based test that is only enabled on nightlies so we don;t see it in the PR, but if you enable the environment variable HYPOTHESIS_ENABLED="true" then you see the failures of the type:

FAILED test_linear_model.py::test_logistic_regression_decision_function[1-100] - ValueError: operands could not be broadcast together with shapes (10,19) (19,10) 

So for now we need to keep this transpose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I don't see this failure locally, and since we changed the output shape I don't see how this could be failing. I also don't see this failure in the logs on CI (failures here were due to an upstream breakage, kicking off a new run now) - is the error you copied local? Are you sure you tested this with a built version of cuml?

@dantegd dantegd changed the base branch from branch-25.02 to branch-25.04 February 9, 2025 00:00
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Feb 9, 2025
Copy link
Member

@dantegd dantegd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After running tests locally had to re-review

@@ -717,8 +717,6 @@ def test_logistic_regression_decision_function(
sklog.classes_ = np.arange(num_classes)

cu_dec_func = culog.decision_function(X_test)
if cu_dec_func.shape[0] > 2: # num_classes
cu_dec_func = cu_dec_func.T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is still required. This is a hypothesis-based test that is only enabled on nightlies so we don;t see it in the PR, but if you enable the environment variable HYPOTHESIS_ENABLED="true" then you see the failures of the type:

FAILED test_linear_model.py::test_logistic_regression_decision_function[1-100] - ValueError: operands could not be broadcast together with shapes (10,19) (19,10) 

So for now we need to keep this transpose

Previously this would return `(n_classes, n_rows)` for multiclass,
whereas sklearn returns `(n_rows, n_classes)`.
@jcrist jcrist force-pushed the decision-function-shape branch from 27109b6 to 3089e69 Compare February 14, 2025 22:28
@jcrist jcrist requested a review from dantegd February 15, 2025 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cuml-cpu Cython / Python Cython or Python issue non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Invalid output from LogisticRegression decision_function.
3 participants