+2 votes
in Machine Learning by (73.8k points)
recategorized by
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

+1 vote
by (349k points)
selected by
 
Best answer

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}


...