def suggest(self, history, searchspace):
<EOL>if '<STR_LIT>' not in sys.modules:<EOL><INDENT>raise ImportError('<STR_LIT>')<EOL><DEDENT>random = check_random_state(self.seed)<EOL>hp_searchspace = searchspace.to_hyperopt()<EOL>trials = Trials()<EOL>for i, (params, scores, status) in enumerate(history):<EOL><INDENT>if status == '<STR_LIT>':<EOL><INDENT>result = {'<STR_LIT>': -np.mean(scores), '<STR_LIT:status>': STATUS_OK}<EOL><DEDENT>elif status == '<STR_LIT>':<EOL><INDENT>result = {'<STR_LIT:status>': STATUS_RUNNING}<EOL><DEDENT>elif status == '<STR_LIT>':<EOL><INDENT>result = {'<STR_LIT:status>': STATUS_FAIL}<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError('<STR_LIT>' % status)<EOL><DEDENT>vals = {}<EOL>for var in searchspace:<EOL><INDENT>if isinstance(var, EnumVariable):<EOL><INDENT>matches = [<EOL>i for i, c in enumerate(var.choices)<EOL>if c == params[var.name]<EOL>]<EOL>assert len(matches) == <NUM_LIT:1><EOL>vals[var.name] = matches<EOL><DEDENT>else:<EOL><INDENT>vals[var.name] = [params[var.name]]<EOL><DEDENT><DEDENT>trials.insert_trial_doc({<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': dict((k, [i]) for k in hp_searchspace.keys()),<EOL>'<STR_LIT>': i,<EOL>'<STR_LIT>': vals,<EOL>'<STR_LIT>': None<EOL>},<EOL>'<STR_LIT:result>': result,<EOL>'<STR_LIT>': i,<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT:state>': <NUM_LIT:2>,<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT>': None,<EOL>'<STR_LIT:version>': <NUM_LIT:0><EOL>})<EOL><DEDENT>trials.refresh()<EOL>chosen_params_container = []<EOL>def suggest(*args, **kwargs):<EOL><INDENT>return tpe.suggest(*args,<EOL>**kwargs,<EOL>gamma=self.gamma,<EOL>n_startup_jobs=self.seeds)<EOL><DEDENT>def mock_fn(x):<EOL><INDENT>chosen_params_container.append(x)<EOL>return <NUM_LIT:0><EOL><DEDENT>fmin(fn=mock_fn,<EOL>algo=tpe.suggest,<EOL>space=hp_searchspace,<EOL>trials=trials,<EOL>max_evals=len(trials.trials) + <NUM_LIT:1>,<EOL>**self._hyperopt_fmin_random_kwarg(random))<EOL>chosen_params = chosen_params_container[<NUM_LIT:0>]<EOL>return chosen_params<EOL>
Suggest params to maximize an objective function based on the
function evaluation history using a tree of Parzen estimators (TPE),
as implemented in the hyperopt package.

Use of this function requires that hyperopt be installed.