3

When I use the XGBoostRegressor to predict the Stock Price, and I try to fit the model.

    # XGBoostRegressor
parameters = {
    'n_estimators': [100, 200, 300, 400],
    'learning_rate': [0.001, 0.005, 0.01, 0.05],
    'max_depth': [8, 10, 12, 15],
    'gamma': [0.001, 0.005, 0.01, 0.02],
    'random_state': [42]
}

eval_set = [(X_train, y_train), (X_valid, y_valid)]
model = xgb.XGBRegressor(eval_set = eval_set, objective = 'reg:squarederror', verbose = False)
clf = GridSearchCV(model, parameters)

clf.fit(X_train, y_train)

print(f'Best params: {clf.best_params_}')
print(f'Best validation score = {clf.best_score_}')

And then I got a WARNING.

Parameters: { "eval_set", "verbose" } might not be used.
  This could be a false alarm, with some parameters getting used by language bindings but
  then being mistakenly passed down to XGBoost core, or some parameter actually being used
  but getting flagged wrongly here. Please open an issue if you find any such cases.

Repeat and Repeat again. I have already changed the parameters, but it did not work. And I did not find any methods to solve it? Did anyone meet this QUESTION? And How to solve it? Thanks.

Max
  • 31
  • 1
  • 2

1 Answers1

5

Pass the eval_set and verbose to fit() and not to XGBRegressor()

clf.fit(X_train, y_train, eval_set=eval_set, verbose=False)

Ref.: https://xgboost.readthedocs.io/en/latest/python/python_api.html?highlight=fit#xgboost.XGBRFRegressor.fit

ferdy
  • 4,396
  • 2
  • 4
  • 16
  • Actually, it's not a problem. It just needs more minutes to calculate. And I executed the code in the console for like 10 minutes, finally got the answer. – Max Nov 26 '21 at 02:42
  • 1
    In the doc its says on XGBRegressor in the note for kwargs: `**kwargs is unsupported by scikit-learn. We do not guarantee that parameters passed via this argument will interact properly with scikit-learn.` So the proper way is to pass the eval_set and verbose in the fit(). verbose is not serious but eval_set if ignored may have consequences on your objective. Up to you of course. – ferdy Nov 26 '21 at 03:56