Skip to content

Instantly share code, notes, and snippets.

@pavlov99
Created November 2, 2016 03:20
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pavlov99/65fe67de331da2f55332630d4a1a4335 to your computer and use it in GitHub Desktop.
Dump xgboost trees visualisation to the file system in pdf format.
model = xgb.Booster(model_file='your.model')
model.feature_names = xgtrain.feature_names # Note: xgtrain is your train file with features.
model.feature_types = xgtrain.feature_types
# Number of trees in the model
num_trees = len(model.get_dump())
# dump all of the trees to tree folder
for tree_index in range(num_trees):
dot = xgb.to_graphviz(model, num_trees=tree_index)
dot.render("trees/tree{}".format(tree_index))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment