我试图在使用optuna进行超参数调优后将XGBClassifier拟合到我的数据集上,但始终收到以下警告:
在目标函数为'binary:logistic'的情况下,默认评估度量从'error'更改为'logloss'
以下是我的代码:
#XGBC MODEL
model = XGBClassifier(random_state = 69)
cross_rfc_score = -1 * cross_val_score(model, train_x1, train_y,
cv = 5, n_jobs = -1, scoring = 'neg_mean_squared_error')
base_rfc_score = cross_rfc_score.mean()
但如果我使用Optuna然后适合获得的参数,就会收到警告。下面是代码:
def objective(trial):
learning_rate = trial.suggest_float('learning_rate', 0.001, 0.01)
n_estimators = trial.suggest_int('n_estimators', 10, 500)
sub_sample = trial.suggest_float('sub_sample', 0.0, 1.0)
max_depth = trial.suggest_int('max_depth', 1, 20)
params = {'max_depth' : max_depth,
'n_estimators' : n_estimators,
'sub_sample' : sub_sample,
'learning_rate' : learning_rate}
model.set_params(**params)
return np.mean(-1 * cross_val_score(model, train_x1, train_y,
cv = 5, n_jobs = -1, scoring = 'neg_mean_squared_error'))
xgbc_study = optuna.create_study(direction = 'minimize')
xgbc_study.optimize(objective, n_trials = 10)
xgbc_study.best_params
optuna_rfc_mse = xgbc_study.best_value
model.set_params(**xgbc_study.best_params)
model.fit(train_x1, train_y)
xgbc_optuna_pred = model.predict(test_x1)
xgbc_optuna_mse1 = mean_squared_error(test_y, xgbc_optuna_pred)
完整的警告如下:
从XGBoost 1.3.0开始,与目标'binary:logistic'一起使用的默认评估指标已从“error”更改为“logloss”。如果您想恢复旧的行为,请明确设置eval_metric。
我想选择MSE
作为我的度量标准。
model.fit(train_x1, train_y, eval_metric='mse')
但是它给我错误,显示为XGBoostError: [21:13:39] ..\src\metric\metric.cc:49: Unknown metric function mse
。 - spectremse
指标,所以我建议使用rmse
,因为它基本上是相同的(一个是另一个的根)。 - Rafamse
,但是为什么要这样做呢?因为你已经有了rmse
,而且它只是为了优化目的(因为你后面还会创建xgbc_optuna_mse1
)。 - Rafa