Search code examples
pythonmachine-learningxgboost

How to get/return max_depth parameter from xgboost (XGBClassifier)?


I trained naive XGBClassifier(). After fitting my classifier has params:

XGBClassifier(base_score=0.5, booster='gbtree', callbacks=None,
              colsample_bylevel=1, colsample_bynode=1, colsample_bytree=1,
              early_stopping_rounds=None, enable_categorical=False,
              eval_metric=None, gamma=0, gpu_id=-1, grow_policy='depthwise',
              importance_type=None, interaction_constraints='',
              learning_rate=0.300000012, max_bin=256, max_cat_to_onehot=4,
              max_delta_step=0, max_depth=6, max_leaves=0, min_child_weight=1,
              missing=nan, monotone_constraints='()', n_estimators=10, n_jobs=0,
              num_parallel_tree=1, objective='binary:logistic',
              predictor='auto', random_state=0, reg_alpha=0, ...)

How can I get max_depth parameter? If I run:

xgbc_naive.max_depth

I get None. Any ideas?


Solution

  • That should be correct, if your model name is xgbc_naive and training went well

    These should all show the max_depth

    model.get_params   
    model.get_xgb_params
    model.max_depth    # should show max_depth used
    

    Did you train with :

    xgbc_naive = XGBClassifier(etc, etc)
    

    P.S. if you saved your model and loaded it again using load_model, try:

    model.score  # show a list of the params used