Decision Labels

I am a newb here, just getting started with machine learning, classification trees, and visualizing classification trees. I cannot seem to figure out how to change where labels appear within the tree. You will notice in this tree, that the label at the root node (“BFOM Score <=82.482”) is present. To me, it would make much more sense to have that label not be in the box, but rather below the box, between the True and false arrows. The same goes for subsequent arrows and labels in the trees. I am thinking I am missing something very simple?

Sample Decision Tree

If I correctly understand your request, I can think of two ways to try to accomplish your goal:

  • xlabel (xlabel | Graphviz) places a label outside the node. But you can’t direct the position, it could end up above, below, right or left.
  • html-like labels (Node Shapes | Graphviz) allow you to explicitly create a text-less node (rectangle) with text below. Html-like nodes are somewhat more fiddly, but one you’ve created one, the rest should be easy.
digraph under {

  node [shape=plaintext]
  overunderA [label=<
    <TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
      <TR>
      <TD height="20" width="100" BORDER="1" bgcolor="lightblue"></TD>
      </TR>
      <TR>
      <TD>stuff on line one<BR/>more on second<BR/>and the long third line</TD>
      </TR>
   </TABLE>>];

  overunderB [label=<
    <TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
      <TR>
      <TD height="20" width="100" BORDER="1" bgcolor="lightblue"></TD>
      </TR>
      <TR>
      <TD>line one<BR/>more<BR/>and the third</TD>
      </TR>
   </TABLE>>];
   
  overunderC [label=<
    <TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0">
      <TR>
      <TD height="20"  width="100" BORDER="1" bgcolor="lightblue"></TD>
      </TR>
      <TR>
      <TD>stuff<BR/>more<BR/>last</TD>
      </TR>
   </TABLE>>];

  overunderA ->  overunderB [label=true]
  overunderA ->  overunderC [label=false]
}

Giving:
labelUnderNode

p.s. if you have more questions, please include your current source file (as preformatted text). It makes it easier to produce an answer.

Thanks for responding Steve. The code I had used was very basic…modeled after some tutorial online:
#use built-in sklearn tree.plot tree method to make a tree from the classifier model
tree.plot_tree(clf_entropy)
dot_data = tree.export_graphviz(clf_entropy,out_file=None,feature_names=X.columns,class_names =clf_entropy.classes_,filled=True)
graph = graphviz.Source(dot_data,format=‘png’)
graph.render(filename=“Decision Tree”,directory=ipath)

I am working with python/scikit-learn here. Not quite sure how to implement what you have written. I suspect I simply don’t understand enough basic concepts about how the dot_data language works and such.