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

Yield stack trace information in resilient mode model_selection warnings #15622

Merged
merged 58 commits into from Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c240a1f
Yield stack trace information in resilient mode warnings
GregoryMorse Nov 13, 2019
7234445
Update _validation.py
GregoryMorse Nov 13, 2019
fc0536b
Update _validation.py
GregoryMorse Nov 13, 2019
0a2f20b
Update _validation.py
GregoryMorse Nov 13, 2019
81243d9
Update _validation.py
GregoryMorse Nov 13, 2019
a182978
Update _validation.py
GregoryMorse Nov 13, 2019
03b5551
Update _validation.py
GregoryMorse Nov 13, 2019
507d14e
Update _testing.py
GregoryMorse Nov 14, 2019
5ef8225
Update _testing.py
GregoryMorse Nov 14, 2019
517a24d
Update _testing.py
GregoryMorse Nov 14, 2019
e7e877b
Update _testing.py
GregoryMorse Nov 14, 2019
eac9acd
Update exceptions.py
GregoryMorse Nov 14, 2019
b0152d9
Update exceptions.py
GregoryMorse Nov 14, 2019
6b910ef
Update exceptions.py
GregoryMorse Nov 14, 2019
9dd28f5
Update exceptions.py
GregoryMorse Nov 14, 2019
f8293cc
Update exceptions.py
GregoryMorse Nov 14, 2019
1cc7593
Update exceptions.py
GregoryMorse Nov 14, 2019
887074c
Update _testing.py
GregoryMorse Nov 14, 2019
0c2d5b5
Update test_validation.py
GregoryMorse Nov 14, 2019
9417c68
Update test_validation.py
GregoryMorse Nov 14, 2019
ea538bb
Update test_validation.py
GregoryMorse Nov 14, 2019
250ce00
Update _validation.py
GregoryMorse Nov 16, 2019
24f619d
Update _validation.py
GregoryMorse Nov 16, 2019
83b8997
Update exceptions.py
GregoryMorse Nov 16, 2019
9e126c7
Update exceptions.py
GregoryMorse Nov 16, 2019
8d1bab0
Update exceptions.py
GregoryMorse Nov 16, 2019
8420287
Update exceptions.py
GregoryMorse Nov 16, 2019
aa3e07f
Update exceptions.py
GregoryMorse Nov 16, 2019
32c490e
Update exceptions.py
GregoryMorse Nov 16, 2019
ec19cdf
Update exceptions.py
GregoryMorse Nov 16, 2019
d62c6e9
Update exceptions.py
GregoryMorse Nov 16, 2019
7d1ca46
Update exceptions.py
GregoryMorse Nov 16, 2019
0fff1aa
Update exceptions.py
GregoryMorse Nov 16, 2019
9bbd066
Update exceptions.py
GregoryMorse Nov 16, 2019
d5f8759
Update exceptions.py
GregoryMorse Nov 17, 2019
8fb7c7f
Update exceptions.py
GregoryMorse Nov 17, 2019
9fdab9b
Update exceptions.py
GregoryMorse Nov 18, 2019
9575a36
Update exceptions.py
GregoryMorse Nov 18, 2019
d746c85
Update exceptions.py
GregoryMorse Nov 18, 2019
fbd3608
Update _testing.py
GregoryMorse Dec 2, 2019
a91d554
Update _testing.py
GregoryMorse Dec 2, 2019
31abfb9
Update test_validation.py
GregoryMorse Dec 2, 2019
f56d290
Update test_validation.py
GregoryMorse Dec 2, 2019
a96d071
Update exceptions.py
GregoryMorse Dec 5, 2019
2fb0e0c
Update exceptions.py
GregoryMorse Dec 5, 2019
7fb1d57
Update exceptions.py
GregoryMorse Dec 5, 2019
2591bd9
Update exceptions.py
GregoryMorse Dec 5, 2019
a7fd33d
Update exceptions.py
GregoryMorse Dec 5, 2019
9ea4276
Update exceptions.py
GregoryMorse Dec 5, 2019
9009f4d
Update exceptions.py
GregoryMorse Dec 6, 2019
dc9b52d
Update exceptions.py
GregoryMorse Dec 6, 2019
c23bd7d
Update exceptions.py
GregoryMorse Dec 6, 2019
029c3cb
TST Fix doctest
thomasjpfan Dec 11, 2019
acf0a22
Update sklearn/model_selection/tests/test_validation.py
GregoryMorse Dec 12, 2019
afd998a
Update test_validation.py
GregoryMorse Dec 12, 2019
97b29aa
Create v0.23.rst
GregoryMorse Dec 13, 2019
f8ab84b
Merge branch 'master' into patch-1
GregoryMorse Dec 13, 2019
4a6919e
Update v0.23.rst
GregoryMorse Dec 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion sklearn/exceptions.py
Expand Up @@ -138,7 +138,10 @@ class FitFailedWarning(RuntimeWarning):
... print(repr(w[-1].message))
FitFailedWarning('Estimator fit failed. The score on this train-test
partition for these parameters will be set to 0.000000.
Details: \\nValueError: Penalty term must be positive; got (C=-2)\\n'...)
Details:
\\nTraceback (most recent call last):...\\nValueError:
Penalty term must be positive; got (C=-2)\\n')


.. versionchanged:: 0.18
Moved from sklearn.cross_validation.
Expand Down
4 changes: 2 additions & 2 deletions sklearn/model_selection/_validation.py
Expand Up @@ -13,7 +13,7 @@
import warnings
import numbers
import time
from traceback import format_exception_only
from traceback import format_exc
from contextlib import suppress

import numpy as np
Expand Down Expand Up @@ -532,7 +532,7 @@ def _fit_and_score(estimator, X, y, scorer, train, test, verbose,
warnings.warn("Estimator fit failed. The score on this train-test"
" partition for these parameters will be set to %f. "
"Details: \n%s" %
(error_score, format_exception_only(type(e), e)[0]),
(error_score, format_exc()),
FitFailedWarning)
else:
raise ValueError("error_score must be the string 'raise' or a"
Expand Down
16 changes: 15 additions & 1 deletion sklearn/model_selection/tests/test_validation.py
Expand Up @@ -1637,8 +1637,22 @@ def test_fit_and_score_failing():
"partition for these parameters will be set to %f. "
"Details: \n%s" % (fit_and_score_kwargs['error_score'],
error_message))

def test_warn_no_trace(msg):
split = msg.splitlines() # note: handles more than '\n'
mtb = split[0] + '\n' + split[-1]
return warning_message in mtb
# check if the same warning is triggered
assert_warns_message(FitFailedWarning, warning_message, _fit_and_score,
assert_warns_message(FitFailedWarning, test_warn_no_trace, _fit_and_score,
GregoryMorse marked this conversation as resolved.
Show resolved Hide resolved
*fit_and_score_args, **fit_and_score_kwargs)

def test_warn_trace(msg):
assert(msg.find('Traceback (most recent call last):\n') > -1)
GregoryMorse marked this conversation as resolved.
Show resolved Hide resolved
split = msg.splitlines() # note: handles more than '\n'
mtb = split[0] + '\n' + split[-1]
return warning_message in mtb
# check traceback is included
assert_warns_message(FitFailedWarning, test_warn_trace, _fit_and_score,
*fit_and_score_args, **fit_and_score_kwargs)

fit_and_score_kwargs = {'error_score': 'raise'}
Expand Down