Visualizing decision tree with feature names The Next CEO of Stack Overflow2019 Community Moderator Electiondecision trees on mix of categorical and real value parametersVisualizing N-way frequency table as a Decision Tree in RDecision Tree generating leaves for only one caseOrdinal feature in decision treeInterpreting Decision Tree in context of feature importancespython sklearn decision tree classifier feature_importances_ with feature names when using continuous valuesa simple way to test wether a tree-based classifier would transfer well to a target population?Visualizing Decision Tree of K-Nearest-Neighbours classifierWhy do we need a gain ratioValue of features is zero in Decision tree Classifier

What is the difference between 翼 and 翅膀?

Reference request: Grassmannian and Plucker coordinates in type B, C, D

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Proper way to express "He disappeared them"

Does soap repel water?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Need help understanding a power circuit (caps and diodes)

is it ok to reduce charging current for li ion 18650 battery?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Flying from Cape Town to England and return to another province

Why the difference in type-inference over the as-pattern in two similar function definitions?

What did we know about the Kessel run before the prologues?

Why isn't the Mueller report being released completely and unredacted?

Why, when going from special to general relativity, do we just replace partial derivatives with covariant derivatives?

Is wanting to ask what to write an indication that you need to change your story?

Math-accent symbol over parentheses enclosing accented symbol (amsmath)

Do I need to write [sic] when a number is less than 10 but isn't written out?

Is French Guiana a (hard) EU border?

What happened in Rome, when the western empire "fell"?

Does increasing your ability score affect your main stat?

Why is information "lost" when it got into a black hole?

If the heap is zero-initialized for security, then why is the stack merely uninitialized?

What was the first Unix version to run on a microcomputer?



Visualizing decision tree with feature names



The Next CEO of Stack Overflow
2019 Community Moderator Electiondecision trees on mix of categorical and real value parametersVisualizing N-way frequency table as a Decision Tree in RDecision Tree generating leaves for only one caseOrdinal feature in decision treeInterpreting Decision Tree in context of feature importancespython sklearn decision tree classifier feature_importances_ with feature names when using continuous valuesa simple way to test wether a tree-based classifier would transfer well to a target population?Visualizing Decision Tree of K-Nearest-Neighbours classifierWhy do we need a gain ratioValue of features is zero in Decision tree Classifier










0












$begingroup$


from scipy.sparse import hstack
X_tr1 = hstack((X_train_cc_ohe, X_train_csc_ohe, X_train_grade_ohe,X_train_price_norm, X_train_tnppp_norm, X_train_essay_bow, X_train_pt_bow)).tocsr()
X_te1 = hstack((X_test_cc_ohe, X_test_csc_ohe, X_test_grade_ohe, X_test_price_norm, X_test_tnppp_norm, X_test_essay_bow, X_test_pt_bow)).tocsr()


X_train_cc_ohe and all are vectorized categorical data, and X_train_pt_bow is bag of words vectorized text data.

Now i applied decision tree classifier on this model, i got this.
enter image description here

i took max_depth as 3 just for visualization purpose.



my question is i want to get feature names in my output instead of index as X2599, X4 etc.

i know i can do it by vect.get_feature_names() as input to export_graphviz, vect is object of CountVectorizer(), since i have already merged this vectorized data using hstack, now how to get feature names in this decision tree.










share|improve this question









$endgroup$
















    0












    $begingroup$


    from scipy.sparse import hstack
    X_tr1 = hstack((X_train_cc_ohe, X_train_csc_ohe, X_train_grade_ohe,X_train_price_norm, X_train_tnppp_norm, X_train_essay_bow, X_train_pt_bow)).tocsr()
    X_te1 = hstack((X_test_cc_ohe, X_test_csc_ohe, X_test_grade_ohe, X_test_price_norm, X_test_tnppp_norm, X_test_essay_bow, X_test_pt_bow)).tocsr()


    X_train_cc_ohe and all are vectorized categorical data, and X_train_pt_bow is bag of words vectorized text data.

    Now i applied decision tree classifier on this model, i got this.
    enter image description here

    i took max_depth as 3 just for visualization purpose.



    my question is i want to get feature names in my output instead of index as X2599, X4 etc.

    i know i can do it by vect.get_feature_names() as input to export_graphviz, vect is object of CountVectorizer(), since i have already merged this vectorized data using hstack, now how to get feature names in this decision tree.










    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      from scipy.sparse import hstack
      X_tr1 = hstack((X_train_cc_ohe, X_train_csc_ohe, X_train_grade_ohe,X_train_price_norm, X_train_tnppp_norm, X_train_essay_bow, X_train_pt_bow)).tocsr()
      X_te1 = hstack((X_test_cc_ohe, X_test_csc_ohe, X_test_grade_ohe, X_test_price_norm, X_test_tnppp_norm, X_test_essay_bow, X_test_pt_bow)).tocsr()


      X_train_cc_ohe and all are vectorized categorical data, and X_train_pt_bow is bag of words vectorized text data.

      Now i applied decision tree classifier on this model, i got this.
      enter image description here

      i took max_depth as 3 just for visualization purpose.



      my question is i want to get feature names in my output instead of index as X2599, X4 etc.

      i know i can do it by vect.get_feature_names() as input to export_graphviz, vect is object of CountVectorizer(), since i have already merged this vectorized data using hstack, now how to get feature names in this decision tree.










      share|improve this question









      $endgroup$




      from scipy.sparse import hstack
      X_tr1 = hstack((X_train_cc_ohe, X_train_csc_ohe, X_train_grade_ohe,X_train_price_norm, X_train_tnppp_norm, X_train_essay_bow, X_train_pt_bow)).tocsr()
      X_te1 = hstack((X_test_cc_ohe, X_test_csc_ohe, X_test_grade_ohe, X_test_price_norm, X_test_tnppp_norm, X_test_essay_bow, X_test_pt_bow)).tocsr()


      X_train_cc_ohe and all are vectorized categorical data, and X_train_pt_bow is bag of words vectorized text data.

      Now i applied decision tree classifier on this model, i got this.
      enter image description here

      i took max_depth as 3 just for visualization purpose.



      my question is i want to get feature names in my output instead of index as X2599, X4 etc.

      i know i can do it by vect.get_feature_names() as input to export_graphviz, vect is object of CountVectorizer(), since i have already merged this vectorized data using hstack, now how to get feature names in this decision tree.







      visualization decision-trees






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 16:45









      torBhakttorBhakt

      1




      1




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          You can use graphviz instead. and use the following code to view the decision tree with feature names.



          import pydotplus
          import sklearn.tree as tree
          from IPython.display import Image

          dt_feature_names = list(X.columns)
          dt_target_names = [str(s) for s in Y.unique()]
          tree.export_graphviz(dt, out_file='tree.dot',
          feature_names=dt_feature_names, class_names=dt_target_names,
          filled=True)
          graph = pydotplus.graph_from_dot_file('tree.dot')
          Image(graph.create_png())


          This will display feature names with values, gini coefficient, sample, value and class






          share|improve this answer









          $endgroup$












          • $begingroup$
            This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
            $endgroup$
            – torBhakt
            Mar 24 at 10:57











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdatascience.stackexchange.com%2fquestions%2f47852%2fvisualizing-decision-tree-with-feature-names%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












          $begingroup$

          You can use graphviz instead. and use the following code to view the decision tree with feature names.



          import pydotplus
          import sklearn.tree as tree
          from IPython.display import Image

          dt_feature_names = list(X.columns)
          dt_target_names = [str(s) for s in Y.unique()]
          tree.export_graphviz(dt, out_file='tree.dot',
          feature_names=dt_feature_names, class_names=dt_target_names,
          filled=True)
          graph = pydotplus.graph_from_dot_file('tree.dot')
          Image(graph.create_png())


          This will display feature names with values, gini coefficient, sample, value and class






          share|improve this answer









          $endgroup$












          • $begingroup$
            This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
            $endgroup$
            – torBhakt
            Mar 24 at 10:57















          0












          $begingroup$

          You can use graphviz instead. and use the following code to view the decision tree with feature names.



          import pydotplus
          import sklearn.tree as tree
          from IPython.display import Image

          dt_feature_names = list(X.columns)
          dt_target_names = [str(s) for s in Y.unique()]
          tree.export_graphviz(dt, out_file='tree.dot',
          feature_names=dt_feature_names, class_names=dt_target_names,
          filled=True)
          graph = pydotplus.graph_from_dot_file('tree.dot')
          Image(graph.create_png())


          This will display feature names with values, gini coefficient, sample, value and class






          share|improve this answer









          $endgroup$












          • $begingroup$
            This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
            $endgroup$
            – torBhakt
            Mar 24 at 10:57













          0












          0








          0





          $begingroup$

          You can use graphviz instead. and use the following code to view the decision tree with feature names.



          import pydotplus
          import sklearn.tree as tree
          from IPython.display import Image

          dt_feature_names = list(X.columns)
          dt_target_names = [str(s) for s in Y.unique()]
          tree.export_graphviz(dt, out_file='tree.dot',
          feature_names=dt_feature_names, class_names=dt_target_names,
          filled=True)
          graph = pydotplus.graph_from_dot_file('tree.dot')
          Image(graph.create_png())


          This will display feature names with values, gini coefficient, sample, value and class






          share|improve this answer









          $endgroup$



          You can use graphviz instead. and use the following code to view the decision tree with feature names.



          import pydotplus
          import sklearn.tree as tree
          from IPython.display import Image

          dt_feature_names = list(X.columns)
          dt_target_names = [str(s) for s in Y.unique()]
          tree.export_graphviz(dt, out_file='tree.dot',
          feature_names=dt_feature_names, class_names=dt_target_names,
          filled=True)
          graph = pydotplus.graph_from_dot_file('tree.dot')
          Image(graph.create_png())


          This will display feature names with values, gini coefficient, sample, value and class







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 22:09









          Cini09Cini09

          166




          166











          • $begingroup$
            This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
            $endgroup$
            – torBhakt
            Mar 24 at 10:57
















          • $begingroup$
            This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
            $endgroup$
            – torBhakt
            Mar 24 at 10:57















          $begingroup$
          This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
          $endgroup$
          – torBhakt
          Mar 24 at 10:57




          $begingroup$
          This won't work, I have main problem in collecting feature names, feature names are build when the model is fitted, in my case I have total 6689 features. I got to know exact number when it throwed an error. Now I don't know how to extract features
          $endgroup$
          – torBhakt
          Mar 24 at 10:57

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • 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.

          Use MathJax to format equations. MathJax reference.


          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%2fdatascience.stackexchange.com%2fquestions%2f47852%2fvisualizing-decision-tree-with-feature-names%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

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

          Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High