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

Skip to content

[MRG + 2] Print train scores in _fit_and_score - #12613

Merged
amueller merged 9 commits into
scikit-learn:masterfrom
marctorsoc:print_train_scores_fit_and_score
Nov 22, 2018
Merged

[MRG + 2] Print train scores in _fit_and_score#12613
amueller merged 9 commits into
scikit-learn:masterfrom
marctorsoc:print_train_scores_fit_and_score

Conversation

@marctorsoc

Copy link
Copy Markdown
Contributor

This small feature was first mentioned (afaik) in Issue #12598

What does this implement/fix? Explain your changes.

It is a simple change in _fit_and_score allowing to print both train and test scores. This is used for different purposes: cross-validation (with any kind of splitter: Kfold, etc), grid/random search, learning curves. I also modified the format so that 3 decimals places are printed only

Any other comments?

There was no documentation for the different verbosity levels, so I left the docstring untouched. Happy to explain what the different levels print if required

@marctorsoc

Copy link
Copy Markdown
Contributor Author

Sorry guys, it's my first PR and have no idea how to solve that code coverage error...

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

These cases are already not covered by tests, so it might not be essential to cover them (although it would be better if they were). Tests can be added in sklearn/model_selection/tests/test_validation.py.

I don't see why we shouldn't just output this data if verbose=2 also, as long as return_train_score=True...

Comment thread sklearn/model_selection/_validation.py Outdated
@amueller

Copy link
Copy Markdown
Member

looks good. maybe a test for multimetric would be nice? Don't have a strong opinion, though.

tests cleaned using pytest parametrize
@marctorsoc marctorsoc changed the title [MRG] Print train scores in _fit_and_score [MRG + 1] Print train scores in _fit_and_score Nov 20, 2018

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

try:
# e.g. unwrap memmapped scalars
score = score.item()
except ValueError:

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.

I don't get what this has to do with the present pull request

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was trying to improve test coverage. Not sure in what situation the item() method can fail (we're checking before that if the object has this method before calling it), that's why I removed that try-except. But can revert that change if you feel was correct (and add a test if you give me an example of how to make it fail)

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.

I don't know why it's useful really, and I don't know why it's not tested, but you can't just remove existing functionality...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah sorry

@marctorrellas if you need help with test tell me I can help =)

@eamanu I would actually appreciate if you can revert my change and add a test for that .item() failure. Or just giving me an example of how to make that to fail in purpose. I mean, can do it totally artificially, but there's a comment there "unwrap memapped scalars" and probably the tests should use that but no clue what it is

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.

Blame shows this commit:
amueller@a08555a
which is not very helpful.
I had assumed this was for dask support, but it would be weird if it was introduced in that PR.
If neither @jnothman nor I know why it's there it's a bit suspect but I wouldn't worry about it for this PR.

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.

(i.e. undo the change)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@eamanu eamanu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@eamanu

eamanu commented Nov 20, 2018

Copy link
Copy Markdown
Contributor

@marctorrellas if you need help with test tell me I can help =)

@marctorsoc marctorsoc changed the title [MRG + 1] Print train scores in _fit_and_score [MRG + 2] Print train scores in _fit_and_score Nov 21, 2018
@marctorsoc

Copy link
Copy Markdown
Contributor Author

I think this is ready for merge

@jnothman

Copy link
Copy Markdown
Member

Please add a brief entry to the change log at doc/whats_new/v0.21.rst. Like the other entries there, please reference this pull request with :issue: and credit yourself (and other contributors if applicable) with :user:

@marctorsoc

Copy link
Copy Markdown
Contributor Author

Please add a brief entry to the change log at doc/whats_new/v0.21.rst. Like the other entries there, please reference this pull request with :issue: and credit yourself (and other contributors if applicable) with :user:

Not really sure if I took the correct labels. Are API and Enhancement ok?

@amueller

Copy link
Copy Markdown
Member

I don't think API is right, just Enhancement probably?

Comment thread doc/whats_new/v0.21.rst Outdated
`return_train_scores` is True and `verbose` > 2.
:issue:`12613` by :user:`Marc Torrellas <marctorrellas>`.

- |API| Additional tests for :func:`_fit_and_score` and :func:`_score`.

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.

I would just remove this item tbh.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@amueller

Copy link
Copy Markdown
Member

sweet, thanks!

@amueller
amueller merged commit f6f7e3c into scikit-learn:master Nov 22, 2018
@jnothman

jnothman commented Nov 25, 2018 via email

Copy link
Copy Markdown
Member

@marctorsoc

Copy link
Copy Markdown
Contributor Author

The what's new entry would avoid referring to private API. It should instead mention affected estimators or public functions. Please submit a pr fixing this. Thanks

sorry for that, see #12669

xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
* print train scores when verbose > 3 in _fit_and_score

* train_scores computed if verbose > 3, and 3 decimals places only

* flake8 warnings solved

* print train score if return_train_score
test coverage increased

* added test for multimetric;
tests cleaned using pytest parametrize

* fixing failed tests for python2...

* revert changes in _scorer

* modified whats_new

* modified whats_new again
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
* print train scores when verbose > 3 in _fit_and_score

* train_scores computed if verbose > 3, and 3 decimals places only

* flake8 warnings solved

* print train score if return_train_score
test coverage increased

* added test for multimetric;
tests cleaned using pytest parametrize

* fixing failed tests for python2...

* revert changes in _scorer

* modified whats_new

* modified whats_new again
@marctorsoc
marctorsoc deleted the print_train_scores_fit_and_score branch February 26, 2022 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants