Get names of columns on which XGBoost Classifier is trained BigQuery

Viewed 127

I am training XGBoost Classifier on Big Query. The model is trained fine and then the bst (saved model) file is imported to a python notebook for plotting. I want to plot the trees present in the model to get an idea of how it is predicted. When I plot the model, I get the results that are given below:

model visualization

I am doing it like this:

import xgboost as xgb
bst = xgb.Booster(model_file='model.bst')
fig, ax = plt.subplots(figsize=(30, 30))
xgb.plot_tree(bst, num_trees=4, ax=ax)
plt.show()

I have come to know that the column names are masked like f182 stands for the 182nd feature that the model was trained on. I would like to create a mapping for these trees, with the actual column names that were used for training the model. The query used to train the model is given below:

CREATE OR REPLACE MODEL `d1.boost_clf1`
OPTIONS(
    MODEL_TYPE='BOOSTED_TREE_CLASSIFIER',
    INPUT_LABEL_COLS=['y'],
    DATA_SPLIT_METHOD='CUSTOM',
    DATA_SPLIT_COL='isTrain',
    AUTO_CLASS_WEIGHTS=TRUE,
    EARLY_STOP=TRUE,
    L2_REG = 0.3,
    ENABLE_GLOBAL_EXPLAIN = TRUE
) AS
SELECT
    * except(isTrain, x1,x2,x3_timestamp,x4_timestamp, y)
    ,isTrain = 1 as isTrain
FROM d1.t1_preprocessed;

I have tried to print bst.feature_names but that doesn't print anything.

Any help in finding a way to plot the trees of XGBoost with actual column names would be highly appreciated. Thanks!

0 Answers
Related