我试图在使用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
作为我选择的度规。
正如这里所描述的,尝试将eval_metric
添加到您的.fit
:
model.fit(train_x1, train_y, eval_metric='rmse')
对rmse
和mse
进行优化得到相同的结果。