in bayesmark/sklearn_funcs.py [0:0]
def __init__(self, model, dataset, scorer, path):
"""Build class that wraps sklearn classifier/regressor CV score for use as an objective function surrogate.
Parameters
----------
model : str
Which classifier to use, must be key in `MODELS_CLF` or `MODELS_REG` dict depending on if dataset is
classification or regression.
dataset : str
Which data set to use, must be key in `DATA_LOADERS` dict, or name of custom csv file.
scorer : str
Which sklearn scoring metric to use, in `SCORERS_CLF` list or `SCORERS_REG` dict depending on if dataset is
classification or regression.
path : str
Root directory to look for all pickle files.
"""
TestFunction.__init__(self)
# Find the space class, we could consider putting this in pkl too
problem_type = get_problem_type(dataset)
assert problem_type in (ProblemType.clf, ProblemType.reg)
_, _, self.api_config = MODELS_CLF[model] if problem_type == ProblemType.clf else MODELS_REG[model]
self.space = JointSpace(self.api_config)
# Load the pre-trained model
fname = SklearnModel.test_case_str(model, dataset, scorer) + ".pkl"
if isinstance(path, bytes):
# This is for test-ability, we could use mock instead.
self.model = pkl.loads(path)
else:
path = os.path.join(path, fname) # pragma: io
assert os.path.isfile(path), "Model file not found: %s" % path
with absopen(path, "rb") as f: # pragma: io
self.model = pkl.load(f) # pragma: io
assert callable(getattr(self.model, "predict", None))