API References

Python package treeplot vizualizes a tree based on a randomforest or xgboost model.

treeplot.treeplot.import_example(data='random', n_samples=1000, n_feat=10)

Import example dataset from sklearn.

Parameters
  • data (str) – ‘random’ : str, two-class ‘breast’ : str, two-class ‘titanic’: str, two-class ‘iris’ : str, multi-class

  • n_samples (int, optional) – Number of samples to generate. The default is 1000.

  • n_feat (int, optional) – Number of features to generate. The default is 10.

Returns

X is the dataset and y the response variable.

Return type

tuple (X,y).

treeplot.treeplot.lgbm(model, featnames=None, num_trees=None, figsize=(25, 25), verbose=3)
treeplot.treeplot.plot(model, featnames=None, num_trees=None, plottype='horizontal', figsize=(25, 25), verbose=3)

Make tree plot for the input model.

Parameters
  • model (model) – xgboost or randomforest model.

  • featnames (list, optional) – list of feature names. The default is None.

  • num_trees (int, default None) – The best performing tree is choosen. Specify any other ordinal number for another target tree

  • plottype (str, (default : 'horizontal')) – Works only in case of xgb model. * ‘horizontal’ * ‘vertical’

  • figsize (tuple, default (25,25)) – Figure size, (height, width)

  • verbose (int, optional) – Print progress to screen. The default is 3. 0: NONE, 1: ERROR, 2: WARNING, 3: INFO (default), 4: DEBUG, 5: TRACE

Returns

ax – Figure axis of the input model.

Return type

Figure axis

treeplot.treeplot.randomforest(model, featnames=None, num_trees=None, filepath='tree', export='png', resolution=100, figsize=(25, 25), verbose=3)

Plot tree based on a randomforest.

Parameters
  • model (model) – randomforest model.

  • featnames (list, optional) – list of feature names. The default is None.

  • num_trees (int, default 0) – Specify the ordinal number of target tree

  • filepath (str, optional) – filename to export. The default is ‘tree’.

  • export (list of str, optional) – Export type. The default is ‘png’. Alternatives: ‘pdf’, ‘png’

  • resolution (int, optional) – resolution of the png file. The default is 100.

  • figsize (tuple, default (25,25)) – Figure size, (height, width)

  • verbose (int, optional) – Print progress to screen. The default is 3. 0: NONE, 1: ERROR, 2: WARNING, 3: INFO (default), 4: DEBUG, 5: TRACE

Returns

ax – Figure axis of the input model.

Return type

Figure axis

treeplot.treeplot.xgboost(model, featnames=None, num_trees=None, plottype='horizontal', figsize=(25, 25), verbose=3)

Plot tree based on a xgboost.

Parameters
  • model (model) – xgboost model.

  • featnames (list, optional) – list of feature names. The default is None.

  • num_trees (int, default None) – The best performing tree is choosen. Specify any other ordinal number for another target tree

  • plottype (str, optional) – Make ‘horizontal’ or ‘vertical’ plot. The default is ‘horizontal’.

  • figsize (tuple, default (25,25)) – Figure size, (height, width)

  • verbose (int, optional) – Print progress to screen. The default is 3. 0: NONE, 1: ERROR, 2: WARNING, 3: INFO (default), 4: DEBUG, 5: TRACE

Returns

ax – Figure axis of the input model.

Return type

Figure axis