Closed ssiegel95 closed 1 year ago
TuneGridSearchCV has the same problem: https://discuss.ray.io/t/valueerror-with-tunegridsearchcv/4138/2
Hi there, what's the status on this please?
Bump
Hey folks, I'll be taking a look at this today.
For whatever it's worth, I was able to hack around this issue with the following
import numpy as np
from sklearn.pipeline import Pipeline
class ErrorRobustPipeline(Pipeline):
"""This is a hacky workaround for
https://github.com/ray-project/tune-sklearn/issues/248.
Its purpose is to catch exceptions that underlying
frameworks such as sklearn throw on invalid parameter
combinations. Once an exception is encountered, internal
state is set such that future scoring attempts will always
return np.nan as an error score."""
def __init__(self, steps, *, memory=None, verbose=False):
super(ErrorRobustPipeline, self).__init__(steps)
self._is_errored = False
def fit(self, X, y=None, **fit_params):
try:
return super(ErrorRobustPipeline, self).fit(X, y, **fit_params)
except Exception as _:
self._is_errored = True
return self
def score(self, X, y=None, sample_weight=None):
try:
return (
np.nan
if self._is_errored
else super(ErrorRobustPipeline, self).score(X, y, sample_weight)
)
except Exception as _:
return np.nan
Running random search using vanilla
RandomizedSearchCV
and then the equivalent operation using tune_sklearn. In the first case, the incorrect parameter combination is gracefully handled by sklearn via theerror_score
parameter being set toint|float
as documented. However, when running the equivalent search usingTuneSearchCV
the entire job fails before completion.