Advertisement
daniilak

Untitled

Feb 2nd, 2022
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def objectiveCat(trial):
  2.     param = {}
  3.     param['learning_rate'] = 0.02
  4.     param['depth'] = trial.suggest_int('depth', 13, 15)
  5.     param['l2_leaf_reg'] = trial.suggest_discrete_uniform('l2_leaf_reg', 4.0, 5.5, 0.5)
  6.     param['min_child_samples'] = trial.suggest_categorical('min_child_samples', [4, 6, 8])
  7.     param['grow_policy'] = 'Depthwise'
  8.     param['iterations'] = trial.suggest_int('iterations', 600, 1000)
  9.     param['use_best_model'] = True
  10.     param['eval_metric'] = 'RMSE'
  11.     param['od_type'] = 'iter'
  12.     param['od_wait'] = 20
  13.     param['random_state'] = 1
  14.     param['logging_level'] = 'Silent'
  15.     regressor = CatBoostRegressor(**param)
  16.  
  17.     regressor.fit(train_X.copy(), train_y.copy(),
  18.                 eval_set=[(val_X.copy(), val_y.copy())],
  19.                 early_stopping_rounds=10)
  20.     loss = mean_squared_error(val_y, regressor.predict(val_X.copy()))
  21.     return loss
  22.  
  23. study = optuna.create_study(study_name=f'catboost-seed{1}')
  24. study.optimize(objectiveCat, n_trials=10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement