我正在使用 Optuna for CatboostRegressor 进行超参数调整,但是我意识到我得到的试验是随机顺序的(我从试验 7 开始,然后是试验 5,然后是试验 8。我在网上看到的所有例子都是按顺序排列的,例如 Trial 0 以值完成:xxxxx、Trial 1、Trial 2...(示例:https ://www.kaggle.com/saurabhshahane/catboost-hyperparameter-tuning-with-optuna )
这是一个问题还是不需要担心?不知道为什么我的顺序是随机的。
还想知道我是否应该做cb.cv
(Catboost 的交叉验证)而不是cb.CatBoostRegressor
然后.fit
和.predict
进行超参数调整?或者我使用哪种方式来获得最佳超参数并不重要?
这是我的代码:
def objective(trial):
optuna_params = {"subsample": trial.suggest_float("subsample", 0.5, 0.99),
'od_wait': trial.suggest_int('od_wait', 10, 50, step=1),
"colsample_bylevel": trial.suggest_float("colsample_bylevel", 0.5, 0.99),
"random_strength": trial.suggest_int("random_strength", 1, 10, step=1),
"l2_leaf_reg": trial.suggest_float("l2_leaf_reg", 1.0, 50.0),
"max_depth": trial.suggest_int("max_depth", 4, 10, step=1),
"n_estimators": trial.suggest_int("n_estimators", 100, 2500, step=1),
'learning_rate': trial.suggest_loguniform("learning_rate", 0.005, 0.1)}
cbregressor = cb.CatBoostRegressor(**optuna_params,
random_state=0,
loss_function='MAE',
eval_metric='MAE',
one_hot_max_size=0,
boost_from_average=True)
cat_optuna = cbregressor.fit(cat_train_pool2, eval_set=cat_val_pool2, verbose=False, early_stopping_rounds=10)
y_valid_pred_cat3 = cat_optuna.predict(X_validation2)
MAE = mean_absolute_error(y_validation, y_valid_pred_cat3)
print('MAE score of CatBoost =', MAE)
return MAE
study = optuna.create_study(direction="minimize", sampler = TPESampler(seed=0), study_name="Catboost Optuna")
study.optimize(objective, n_trials=100, n_jobs=-1)