Python API num_boosted_rounds

I am using xgboost 1.3.3
That is the version conda installs by default

when I want to get the number of trees from a booster via


I get

AttributeError: 'Booster' object has no attribute 'num_boosted_rounds'

In the docs I gather the method should be present

Any hint what I am doing wrong and/or how to get the number of trees from a booster?

Thx & best

Try booster.num_boosted_rounds(), since it is a method, not an attribute.

Thank you very much for your reply!

The error stays the same. I actually forgot to post the brackets in the first post, the command was executed with them.

When I access a method without () it still recognizes that there is something there. Any other idea what it might be? Or any other idea how I would get the tree count?

<bound method Booster.predict of <xgboost.core.Booster object at 0x7f31df6a5550>>

I can’t reproduce the error on my part. I ran this script successfully:

import xgboost as xgb
from sklearn.datasets import load_boston

X, y = load_boston(return_X_y=True)
dtrain = xgb.DMatrix(X, label=y)
params = {'objective': 'reg:squarederror', 'eval_metric': 'rmse',
          'max_depth': 4, 'learning_rate': 0.5}
bst = xgb.train(params, dtrain, num_boost_round=10, evals=[(dtrain, 'train')])
print(bst.num_boosted_rounds())  # prints 10

Can you run this script on your machine and see if it works?

I can run the script and get the same error

I have installed xgboost via
conda install xgboost
which installes version 1.3.3
All of my models that are used in production are running fine …
Do you know if 1.3.3 does not have this function?
Do you know if there is another way of getting the number of trees from a booster?
I am thinking of something hackish like
len(bst.trees_to_dataframe()['Tree'].unique()) #prints 10

when I update the xgboost version to 1.4.0 in another conda environment your code executes perfectly to 10