Fork me on GitHub

sklearn.exceptions.FitFailedWarning

class sklearn.exceptions.FitFailedWarning[source]

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.model_selection 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))
... 
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)',)",)
Previous