Skip to content

MAINT validate parameters in LogisticRegression and LogisiticRegressionCV - #23565

Merged
glemaitre merged 31 commits into
scikit-learn:mainfrom
Jitensid:logistic_regression_validate_params
Jun 27, 2022
Merged

glemaitre merged 31 commits into
scikit-learn:mainfrom
Jitensid:logistic_regression_validate_params

Conversation

@Jitensid

@Jitensid Jitensid commented Jun 8, 2022 •

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Logistic Regression and Logistic Regression CV uses _validate_parameters as part of #23462

What does this implement/fix? Explain your changes.

  1. Logistic Regression and Logistic Regression CV has a new class attribute _parameter_constraints that defines the valid types and values for the parameters.
  2. fit method first calls self._validate_params() method.
  3. Removed the code for simple param validation for both the estimators.

Any other comments?

  1. The test_check_solver_option test was failing because of assertion error due to mismatch of error messages. As of now I removed match=msg from it as I am not sure what to do about it.

This is my first contribution. If I missed anything let me know I will fix it as soon as possible.

@Jitensid Jitensid changed the title [MRG] Logistic regression and Logistic Regression use _validate_params [MRG] Logistic regression and Logistic Regression CV use _validate_params Jun 8, 2022
@Jitensid

Jitensid commented Jun 8, 2022 •

Copy link
Copy Markdown
Contributor Author

Closed the Pull Request because of failure of tests.

@Jitensid Jitensid closed this Jun 8, 2022
@Jitensid Jitensid reopened this Jun 8, 2022
@Jitensid

Jitensid commented Jun 8, 2022

Copy link
Copy Markdown
Contributor Author

Removed tests that were validating error messages for Logistic Regression and Logistic Regression CV estimators.

@Jitensid Jitensid changed the title [MRG] Logistic regression and Logistic Regression CV use _validate_params [WIP] Logistic regression and Logistic Regression CV use _validate_params Jun 8, 2022

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR @Jitensid. Here are some suggestions

Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
@Jitensid Jitensid changed the title [WIP] Logistic regression and Logistic Regression CV use _validate_params [MRG] Logistic regression and Logistic Regression CV use _validate_params Jun 11, 2022
@jeremiedbb jeremiedbb added the Validation related to input validation label Jun 13, 2022
@Jitensid
Jitensid requested a review from jeremiedbb June 15, 2022 08:57
@jeremiedbb

Copy link
Copy Markdown
Member

@Jitensid I directly pushed some small fixes. Otherwise LGTM

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@glemaitre
glemaitre self-requested a review June 24, 2022 15:28
@glemaitre glemaitre changed the title [MRG] Logistic regression and Logistic Regression CV use _validate_params MAINT validate parameters in LogisticRegression and LogisiticRegressionCV Jun 24, 2022
Comment thread sklearn/linear_model/_logistic.py Resolved
Comment thread sklearn/linear_model/_logistic.py Resolved
@Jitensid

Copy link
Copy Markdown
Contributor Author

@glemaitre I have made changes as per your suggestions.

@glemaitre

Copy link
Copy Markdown
Member

I don't think that we need the test test_multinomial_validation:

@pytest.mark.parametrize("solver", ["lbfgs", "newton-cg", "sag", "saga"])
def test_multinomial_validation(solver):
    lr = LogisticRegression(C=-1, solver=solver, multi_class="multinomial")

    with pytest.raises(ValueError):
        lr.fit([[0, 1], [1, 0]], [0, 1])

C is negative and will be caught by the common parameter validation

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise LGTM

@Jitensid

Copy link
Copy Markdown
Contributor Author

Removed the test_multinomial_validation since C=-1 will cause ValueError and it is handled by param validation

@glemaitre
glemaitre merged commit 1f0c7e9 into scikit-learn:main Jun 27, 2022
@glemaitre

Copy link
Copy Markdown
Member

Thanks @Jitensid All good to be merged.

@Jitensid

Copy link
Copy Markdown
Contributor Author

Thanks @Jitensid All good to be merged.

Thank you @jeremiedbb @glemaitre for making my first open source contribution experience memorable.

ogrisel pushed a commit to ogrisel/scikit-learn that referenced this pull request Jul 11, 2022
…onCV (scikit-learn#23565)

Co-authored-by: jeremie du boisberranger <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants