从LightGBM模型访问树和节点 [英] Access trees and nodes from LightGBM model

查看:603
本文介绍了从LightGBM模型访问树和节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sci-kit学习中,可以访问整个树结构,即树的每个节点。这样可以探究在树的每个分割处使用的属性以及用于测试的值

In sci-kit learn, it's possible to access the entire tree structure, that is, each node of the tree. This allows to explore the attributes used at each split of the tree and which values are used for the test

The binary tree structure has 5 nodes and has the following tree structure:
node=0 test node: go to node 1 if X[:, 3] <= 0.800000011920929 else to node 2.
    node=1 leaf node.
    node=2 test node: go to node 3 if X[:, 2] <= 4.950000047683716 else to node 4.
            node=3 leaf node.
            node=4 leaf node.

Rules used to predict sample 0:
decision id node 0 : (X_test[0, 3] (= 2.4) > 0.800000011920929)
decision id node 2 : (X_test[0, 2] (= 5.1) > 4.950000047683716)

对于随机森林,您可以获得通过在所有决策树之间循环遍历相同的信息

For the Random Forest, you can obtain the same information by looping across all the decision trees

for tree in model.estimators_:
    # extract info from tree

是否可以从LightGBM模型中提取相同的信息?也就是说,您可以访问:a)每棵树和b)一棵树的每个节点吗?

Can the same information be extracted from a LightGBM model? That is, can you access: a) every tree and b) every node of a tree?

推荐答案

是的,这是可能的

model._Booster.dump_model()["tree_info"]

例如在 lightgbm.plot_tree()中使用。我必须承认,尽管我自己并没有使用过它,也不知道有关返回的结构的详细信息。

which is for example used in lightgbm.plot_tree(). I must admit though that I haven't used it myself and don't know the details about the returned structure.

这篇关于从LightGBM模型访问树和节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆