Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX validate parameters in fit in all SVM estimators - #21436

Merged
jjerphan merged 10 commits into
scikit-learn:mainfrom
Haidar13:estimatorValidation
Nov 5, 2021
Merged

FIX validate parameters in fit in all SVM estimators#21436
jjerphan merged 10 commits into
scikit-learn:mainfrom
Haidar13:estimatorValidation

Conversation

@Haidar13

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Addresses #21406

What does this implement/fix? Explain your changes.

Moves ValueError checks from _init_ to fit

Any other comments?

#DataUmbrella

@glemaitre

glemaitre commented Oct 23, 2021

Copy link
Copy Markdown
Member

I think that we should add an entry in the changelog since it could have an effect on third-party libraries.

Please add an entry to the change log at doc/whats_new/v1.1.rst. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:. For instance, it should look like:

- |Fix| :class:`smv.SVM` (and add all the other impacted classes) nows validate input parameters in `fit`
  instead of `__init__`.
  :pr:`21436` by :user:`Haidar Almubarak   <Haidar13 >`.

It should in the section:

:mod:`sklearn.svm`

@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.

Apart from that everything looks good. We already have the proper test calling fit.

Comment thread sklearn/svm/_base.py Outdated
Comment thread sklearn/svm/_base.py Outdated
@glemaitre glemaitre changed the title Moving parameter validation from __init__ to fit for SVM estimators FIX validate parameters in fit in all SVM estimators Oct 23, 2021

@thomasjpfan thomasjpfan 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.

Thank you for the PR @Haidar13 !

Comment thread sklearn/svm/_base.py Outdated
@Haidar13

Copy link
Copy Markdown
Contributor Author

The last update gave coverage issues for the test.

There is test_svm_gamma_error in test_svm.py but the condition and message in the test are not the same as the ones in the codebase.

def test_svm_gamma_error(Estimator, data):
X, y = data
est = Estimator(gamma="auto_deprecated")
err_msg = "When 'gamma' is a string, it should be either 'scale' or 'auto'"
with pytest.raises(ValueError, match=err_msg):
est.fit(X, y)

Do you want to merge this PR and create another issue/PR for test coverage or put it all in one PR?

@glemaitre

Copy link
Copy Markdown
Member

No this is better to cover the missing case in this PR. This is related to the PR itself.

Comment thread doc/whats_new/v1.1.rst Outdated

@ogrisel ogrisel 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.

Indeed, please add the missing tests to cover the checks as part of this PR.

Comment thread sklearn/svm/_base.py
@Haidar13

Copy link
Copy Markdown
Contributor Author

I just pushed the updated code with the tests added.

Just one comment, flake8 did not catch everything that the linter in the Github action complained about. I saw that one of the actions was using black, I installed black and let it reformat the file then everything went well. what linter is used here?

@glemaitre

Copy link
Copy Markdown
Member

We are using flake8 on the diff and black on all files if I recall well.

@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.

Still my +1. Maybe @ogrisel or @thomasjpfan want to have a look here during the sprint.

Comment thread sklearn/svm/_base.py Outdated

@ogrisel ogrisel 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.

Note: I pushed some commits to resolve the conflict with main. Don't forget to pull before adding new changes.

There are missing periods in the error messages (see below). I am also suggesting to use the !r format to use repr(self.gamma) which is more informative than str(self.gamma) in error messages.

The tests will need to be adjusted accordingly. Once done, +1 for merge on my side.

Comment thread sklearn/svm/_base.py Outdated
Comment thread sklearn/svm/_base.py Outdated
@Haidar13

Haidar13 commented Nov 4, 2021

Copy link
Copy Markdown
Contributor Author

Done, periods added and repr is now used to print the gamma instead of str

@jjerphan jjerphan 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. Thank you, @Haidar13!

@jjerphan
jjerphan merged commit 8d3304a into scikit-learn:main Nov 5, 2021
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Nov 29, 2021
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
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.

6 participants