The fmin function should be of the form:
def evaluate_hyperparams(params):
"""
This method will be passed to `hyperopt.fmin()`. It fits and evaluates the model using the given hyperparameters to get the validation loss.
:param params: This dict of parameters specifies hyperparameter values to test.
:return: dict with fields 'loss' (scalar loss) and 'status' (success/failure status of run)
"""
# Train the model
model, score = train(params)
return {'loss': score, 'status': STATUS_OK}
The `train` function can be any arbitrary function that trains a model and returns both the fitted model class and the score metric of interest (RMSE, for example).