+1 vote
in Programming Languages by (8.7k points)
I am using a trained XGboost model for the prediction task. The model was trained and saved as a pickle file. I want to check the hyperparameters that were used for training the model. How can I fetch those hyperparameters?

1 Answer

0 votes
by (17k points)
edited by

If you have used sklearn wrapper of xgboost, you can use function get_xgb_params() to retrieve hyperparameters of the saved model. If you have used the core xgboost, I am not sure if there exists a function.

Here is an example:

bst = pickle.load(open(modelName, 'rb'))
print(bst.get_xgb_params())

The above code will display an output something like the following:

{'base_score': 0.5, 'booster': 'gbtree', 'colsample_bylevel': 1, 'colsample_bynode': 1, 'colsample_bytree': 0.5, 'gamma': 0.01, 'learning_rate': 0.1, 'max_delta_step': 0, 'max_depth': 5, 'min_child_weight': 0, 'missing': nan, 'n_estimators': 39, 'nthread': 8, 'objective': 'binary:logistic', 'reg_alpha': 0, 'reg_lambda': 1, 'scale_pos_weight': 63.6, 'seed': 1234, 'silent': 1, 'subsample': 0.9, 'verbosity': 1, 'eta': 0.2}

...