34

I saw that some xgboost methods take a parameter num_boost_round, like this:

model = xgb.cv(params, dtrain,  num_boost_round=500, early_stopping_rounds=100)

Others however take n_estimators like this:

model_xgb = xgb.XGBRegressor(n_estimators=360, max_depth=2, learning_rate=0.1)

As far as I understand, each time boosting is applied a new estimator is created. Is that nor correct?

If that is so, then the numbers num_boost_round and n_estimators should be equal, right?

yatu
  • 86,083
  • 12
  • 84
  • 139
bsky
  • 19,326
  • 49
  • 155
  • 270
  • 13
    Yes you are correct. Please look at the following question: [How to get Predictions with XGBoost and XGBoost using Scikit-Learn Wrapper to match?](https://stackoverflow.com/questions/46943674/how-to-get-predictions-with-xgboost-and-xgboost-using-scikit-learn-wrapper-to-ma) – Vivek Kumar Jan 02 '18 at 11:47

2 Answers2

22

Yes they are the same, both referring to the same parameter (see the docs here, or the github issue).

The reason of the different name is because xgb.XGBRegressor is an implementation of the scikit-learn API; and scikit-learn conventionally uses n_estimators to refer to the number of boosting stages (for example the GradientBoostingClassifier)

Tin Lai
  • 440
  • 3
  • 8
  • The author of xgboost also uses `n_estimators` in xgbclassfier and `num_boost_round`, got knows why in the same api he wants to do this. :( – agent18 Jan 20 '21 at 17:37
  • 1
    I accidentally set both of them to a high number during the same optimization and the optimization time seems to have multiplied. I wonder if setting them both to 1000 is equivalent to setting the boosting rounds to a million. – Wilmer E. Henao Aug 12 '21 at 13:28
0

num_parallel_tree in XGBoost native API is equivalent to n_estimators.

t98907
  • 2,287
  • 2
  • 13
  • 7