-1

Among the most popular packages used in modelling problems, there are plenty functions which allow converting the model object into something that can be understood by humans, e.g. xgb.model.dt.tree in xgboost or pretty.gbm.tree in GBM. Is there any similar function in the catboost package or any other possibility to represent a model as, for instance, data frame? An object of catboost.Model class is a list with external pointer and raw data elements and the only way to find some info about the structure of model is to save it as a .py file but it's rather a harsh way.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
pk09890
  • 13
  • 1

1 Answers1

3

There is a tree_idx attribute, but it can be used only for tree visualization with plot_tree, and not directly with model; here's a reproducible example with the Boston data:

import numpy as np
import catboost
from catboost import CatBoostRegressor
from sklearn.datasets import load_boston

boston = load_boston()
y = boston['target']
X = boston['data']

model = CatBoostRegressor(depth=2, verbose=False, iterations=5).fit(X, y)

model.plot_tree(tree_idx=0)

enter image description here

model.plot_tree(tree_idx=4)

enter image description here

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • what does the val in leaves mean? – Nauman Naeem Aug 13 '20 at 20:12
  • @NaumanNaeem this is a regression tree, so the values shown are the mean values of the samples that ended up in the respective terminal nodes (leaves). – desertnaut Aug 13 '20 at 23:37
  • Similar values appear when I use catboost classifier, [binary](https://imgur.com/pB80Dtr) as well as [multiclass](https://imgur.com/rrXL0Hc), I'm not sure to what to make of these values. The official tutorial notebook on visualization doesn't mention anything about these. – Nauman Naeem Aug 14 '20 at 06:07
  • @NaumanNaeem comments is not the right space to discuss such things. If you are facing issues, you are very welcome to open a question. – desertnaut Aug 14 '20 at 17:59
  • Thanks, I have actually posted a question that no one answered. Maybe you want to take a [look](https://stackoverflow.com/questions/63407613/catboos-plot-tree-understanding). – Nauman Naeem Aug 17 '20 at 13:41