Access trees and nodes from LightGBM model












0















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


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?










share|improve this question



























    0















    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


    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?










    share|improve this question

























      0












      0








      0








      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


      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?










      share|improve this question














      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


      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?







      nodes random-forest decision-tree lightgbm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 12:17









      Titus PulloTitus Pullo

      1,29872848




      1,29872848
























          1 Answer
          1






          active

          oldest

          votes


















          0














          LightGBM has almost the same functions with XGBoost; sometimes I even go to the XGBoost documentation to find the functions of LightGBM. You can search for how it is done in XGBoost or you can refer directly to: https://github.com/Microsoft/LightGBM/issues/845



          Also, LightGBM has a sklearn wrapper, it is probably possible to use the sklearn structure on the model you train as the way you shared. You may want to have a look at: https://lightgbm.readthedocs.io/en/latest/_modules/lightgbm/sklearn.html



          Hope I could help, please do not hesitate to write if not resolved; I will go deeper in details.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280845%2faccess-trees-and-nodes-from-lightgbm-model%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            LightGBM has almost the same functions with XGBoost; sometimes I even go to the XGBoost documentation to find the functions of LightGBM. You can search for how it is done in XGBoost or you can refer directly to: https://github.com/Microsoft/LightGBM/issues/845



            Also, LightGBM has a sklearn wrapper, it is probably possible to use the sklearn structure on the model you train as the way you shared. You may want to have a look at: https://lightgbm.readthedocs.io/en/latest/_modules/lightgbm/sklearn.html



            Hope I could help, please do not hesitate to write if not resolved; I will go deeper in details.






            share|improve this answer




























              0














              LightGBM has almost the same functions with XGBoost; sometimes I even go to the XGBoost documentation to find the functions of LightGBM. You can search for how it is done in XGBoost or you can refer directly to: https://github.com/Microsoft/LightGBM/issues/845



              Also, LightGBM has a sklearn wrapper, it is probably possible to use the sklearn structure on the model you train as the way you shared. You may want to have a look at: https://lightgbm.readthedocs.io/en/latest/_modules/lightgbm/sklearn.html



              Hope I could help, please do not hesitate to write if not resolved; I will go deeper in details.






              share|improve this answer


























                0












                0








                0







                LightGBM has almost the same functions with XGBoost; sometimes I even go to the XGBoost documentation to find the functions of LightGBM. You can search for how it is done in XGBoost or you can refer directly to: https://github.com/Microsoft/LightGBM/issues/845



                Also, LightGBM has a sklearn wrapper, it is probably possible to use the sklearn structure on the model you train as the way you shared. You may want to have a look at: https://lightgbm.readthedocs.io/en/latest/_modules/lightgbm/sklearn.html



                Hope I could help, please do not hesitate to write if not resolved; I will go deeper in details.






                share|improve this answer













                LightGBM has almost the same functions with XGBoost; sometimes I even go to the XGBoost documentation to find the functions of LightGBM. You can search for how it is done in XGBoost or you can refer directly to: https://github.com/Microsoft/LightGBM/issues/845



                Also, LightGBM has a sklearn wrapper, it is probably possible to use the sklearn structure on the model you train as the way you shared. You may want to have a look at: https://lightgbm.readthedocs.io/en/latest/_modules/lightgbm/sklearn.html



                Hope I could help, please do not hesitate to write if not resolved; I will go deeper in details.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 11:47









                Ugur MULUKUgur MULUK

                2566




                2566






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280845%2faccess-trees-and-nodes-from-lightgbm-model%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python