How to get trained trees from Catboost?

2.3k views Asked by At

I used --print-trees --verbose to print trees and get output like this:

441:
(f3, split0) score -0.01684494315
(f1, split0) score 0.00728615875
(f3, split0) score 0.02879532296
learn 0.1080262936passed: 0.00033 sec   total: 234ms    remaining: 30.7ms
442:
(f0, split0) score 0.02581825636
(f0, split0) score -0.05604439647
learn 0.1080003503passed: 0.000278 sec  total: 234ms    remaining: 30.1ms

How can I get split values and result class for each tree?

2

There are 2 answers

0
Anna Veronika Dorogush On

You can convert the model to CoreML format, it is a proto format from which you can get all split values and leaf values. CoreML format doesn't support statistics on categorical features yet, so it is currently not possible to have a human readable model with these statistics. But we will add it later, there is an issue on GitHub for that: https://github.com/catboost/catboost/issues/23

1
Peng On

Check out this one: https://blog.csdn.net/l_xzmy/article/details/81532281

The idea is to draw trees from the detail info of the exported model:

cat_clf.save_model(fname, format="cbm", export_parameters=None)