-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG + 1] move custom error/warning classes into sklearn.exceptions (and move deprecated
away from utils.__init__.py
)
#4826
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3afc0e
MAINT move custom error/warning classes into sklearn.exceptions
raghavrv 09f0fa7
DOC/SPHINX Add template for classes which don't have init (Exception …
raghavrv e19a981
MAINT Deprecated the UndefinedMetricWarning at sklearn.metrics.base
raghavrv 61ae8d5
MAINT move deprecated into deprecation.py
raghavrv 857cb09
FIX/ENH Make the moved class resilient to the deprecation patching
raghavrv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
:mod:`{{module}}`.{{objname}} | ||
{{ underline }}============== | ||
|
||
.. currentmodule:: {{ module }} | ||
|
||
.. autoclass:: {{ objname }} | ||
|
||
.. include:: {{module}}.{{objname}}.examples | ||
|
||
.. raw:: html | ||
|
||
<div class="clearer"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
""" | ||
The :mod:`sklearn.exceptions` module includes all custom warnings and error | ||
classes used across scikit-learn. | ||
""" | ||
|
||
__all__ = ['NotFittedError', | ||
'ChangedBehaviorWarning', | ||
'ConvergenceWarning', | ||
'DataConversionWarning', | ||
'DataDimensionalityWarning', | ||
'EfficiencyWarning', | ||
'FitFailedWarning', | ||
'NonBLASDotWarning', | ||
'UndefinedMetricWarning'] | ||
|
||
|
||
class NotFittedError(ValueError, AttributeError): | ||
"""Exception class to raise if estimator is used before fitting. | ||
|
||
This class inherits from both ValueError and AttributeError to help with | ||
exception handling and backward compatibility. | ||
|
||
Examples | ||
-------- | ||
>>> from sklearn.svm import LinearSVC | ||
>>> from sklearn.exceptions import NotFittedError | ||
>>> try: | ||
... LinearSVC().predict([[1, 2], [2, 3], [3, 4]]) | ||
... except NotFittedError as e: | ||
... print(repr(e)) | ||
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS | ||
NotFittedError('This LinearSVC instance is not fitted yet',) | ||
""" | ||
|
||
|
||
class ChangedBehaviorWarning(UserWarning): | ||
"""Warning class used to notify the user of any change in the behavior.""" | ||
|
||
|
||
class ConvergenceWarning(UserWarning): | ||
"""Custom warning to capture convergence problems""" | ||
|
||
|
||
class DataConversionWarning(UserWarning): | ||
"""Warning used to notify implicit data conversions happening in the code. | ||
|
||
This warning occurs when some input data needs to be converted or | ||
interpreted in a way that may not match the user's expectations. | ||
|
||
For example, this warning may occur when the the user | ||
- passes an integer array to a function which expects float input and | ||
will convert the input | ||
- requests a non-copying operation, but a copy is required to meet the | ||
implementation's data-type expectations; | ||
- passes an input whose shape can be interpreted ambiguously. | ||
""" | ||
|
||
|
||
class DataDimensionalityWarning(UserWarning): | ||
"""Custom warning to notify potential issues with data dimensionality. | ||
|
||
For example, in random projection, this warning is raised when the | ||
number of components, which quantifes the dimensionality of the target | ||
projection space, is higher than the number of features, which quantifies | ||
the dimensionality of the original source space, to imply that the | ||
dimensionality of the problem will not be reduced. | ||
""" | ||
|
||
|
||
class EfficiencyWarning(UserWarning): | ||
"""Warning used to notify the user of inefficient computation. | ||
|
||
This warning notifies the user that the efficiency may not be optimal due | ||
to some reason which may be included as a part of the warning message. | ||
This may be subclassed into a more specific Warning class. | ||
""" | ||
|
||
|
||
class FitFailedWarning(RuntimeWarning): | ||
"""Warning class used if there is an error while fitting the estimator. | ||
|
||
This Warning is used in meta estimators GridSearchCV and RandomizedSearchCV | ||
and the cross-validation helper function cross_val_score to warn when there | ||
is an error while fitting the estimator. | ||
|
||
Examples | ||
-------- | ||
>>> from sklearn.grid_search import GridSearchCV | ||
>>> from sklearn.svm import LinearSVC | ||
>>> from sklearn.exceptions import FitFailedWarning | ||
>>> import warnings | ||
>>> warnings.simplefilter('always', FitFailedWarning) | ||
>>> gs = GridSearchCV(LinearSVC(), {'C': [-1, -2]}, error_score=0) | ||
>>> X, y = [[1, 2], [3, 4], [5, 6], [7, 8], [8, 9]], [0, 0, 0, 1, 1] | ||
>>> with warnings.catch_warnings(record=True) as w: | ||
... try: | ||
... gs.fit(X, y) # This will raise a ValueError since C is < 0 | ||
... except ValueError: | ||
... pass | ||
... print(repr(w[-1].message)) | ||
... # doctest: +NORMALIZE_WHITESPACE | ||
FitFailedWarning("Classifier 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)',)",) | ||
""" | ||
|
||
|
||
class NonBLASDotWarning(EfficiencyWarning): | ||
"""Warning used when the dot operation does not use BLAS. | ||
|
||
This warning is used to notify the user that BLAS was not used for dot | ||
operation and hence the efficiency may be affected. | ||
""" | ||
|
||
|
||
class UndefinedMetricWarning(UserWarning): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this guy should have a description.