text_plain_output_1.png
from catboost import CatBoostRegressor

from lightgbm import LGBMRegressor

from sklearn.ensemble import GradientBoostingRegressor

from sklearn.ensemble import RandomForestRegressor

from sklearn.neighbors import KNeighborsRegressor

from sklearn.neural_network import MLPRegressor

from xgboost import XGBRegressor

import skopt

knn_reg = KNeighborsRegressor(n_jobs=-1)
mlp_reg = MLPRegressor()
rf_reg = RandomForestRegressor(n_jobs=-1)
gb_reg = GradientBoostingRegressor()
xgb_reg = XGBRegressor(n_jobs=-1)
lgbm_reg = LGBMRegressor(n_jobs=-1)
cat_reg = CatBoostRegressor()

search_space = [skopt.space.Integer(4, 12, name='max_depth'), skopt.space.Integer(50, 200, name='n_estimators'), skopt.space.Integer(17, 24, name='max_features'), skopt.space.Real(0.0, 1.0, name='min_impurity_decrease'), skopt.space.Categorical(categories=[True, False], name='bootstrap')]

evaluator = Params_Evaluate(X_train, X_val, Y_train, Y_val)

evaluator.select_model(rf_reg)

@skopt.utils.use_named_args(search_space)
def objective(**params):
    return evaluator.evaluate_params(params)

def to_named_params(results, search_space):
    params = results.x
    param_dict = {}
    params_list = [(dimension.name, param) for dimension, param in zip(search_space, params)]
    for item in params_list:
        param_dict[item[0]] = item[1]
    return param_dict

search_space_xgb = [skopt.space.Integer(4, 12, name='max_depth'), skopt.space.Real(0.0, 1.0, name='eta'), skopt.space.Real(0.0, 1.0, name='subsample'), skopt.space.Categorical(categories=['gbtree', 'dart'], name='booster')]

best_params_gxb = to_named_params(results_xgb, search_space_xgb)
best_xgb_reg = xgb_reg.set_params(**best_params_gxb)
best_xgb_reg