@staticmethod
    def get_best_params(model, training, testing, non_relevant_count=100, **kwargs):
        # Create a grid of parameters
        kwargs = kwargs or model.param_details()
        grid = zip(*(x.flat for x in np.mgrid[[slice(*row[:3]) for row in kwargs.values()]]))
        m_instance = model()
        values = {k: ParameterTuning.tune(m_instance, training, testing, non_relevant_count,
                                          **dict(zip(kwargs.keys()[:2], k)))
                  for k in zip(*(v[:2] for v in kwargs.values()))}

        gp = GaussianProcess(theta0=.1, thetaL=.001, thetaU=5.)

        # To make it reasonable we limit the number of iterations
        for i in xrange(0, ParameterTuning.__max_iterations):

            # Get a list of parameters and the correspondent result
            param, response = zip(*values.items())

            # Fit the GaussianProcess model with the parameters and results
            gp.fit(np.array(param), np.array(response).T)

            # Get prediction
            y_predicted, mse = gp.predict(grid, eval_MSE=True)

            # get upper confidence interval. 2.576 z-score corresponds to 99th
            # percentile
            ucb_u = y_predicted + np.sqrt(mse) * ParameterTuning.__z_score

            next_list = zip(ucb_u, grid)
            next_list.sort(reverse=True)
            new_x = next_list[0][1]

            if new_x not in values:
                values[new_x] = ParameterTuning.tune(m_instance, training, testing, 
                                                     **{k: v for k, v in zip(kwargs, new_x)})
            else:
                break
        sv = sorted(values.items(), cmp=lambda x, y: cmp(y[1], x[1]))
        assert sv[0][1] > sv[-1][1], "Sorted from lowest to highest"
        return {k: v for k, v in zip(kwargs, sv[0][0])}
Search for the best set of parameters in the model
dataset/ETHPy150Open grafos-ml/test.fm/src/testfm/evaluation/parameter_tuning.py/ParameterTuning.get_best_params