Search code examples
pythonrmachine-learningcatboost

Representation of catboost model in a human-interpretable manner


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.


Solution

  • 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