California Investment Network


Recent Blog


Pitching Help Desk


Testimonials

"Thank you very much for the extra input with my Restaurant/Nightclub proposal. I already have a couple investors who are requesting more info, and that's less than 24hrs after submitting the proposal to you. I am very pleased."
Rodrick Agcaoili

 BLOG >> Recent

Improved Decision Tree Layout [Decision Trees
Posted on September 3, 2013 @ 05:34:00 AM by Paul Meagher

To date I have not been fully satisfied with how my decision trees have appeared. They did not appear to use space efficiently and they were not as easy to read as I would have liked. Today we will make some improvements to a Graphviz recipe for constructing decision trees. These improvements will make for a more space efficient decision tree that is also easier to read.

The main improvements I have made are:

  • All of the labelling for actions and events appears on the edges instead of the nodes. In previous examples, most labelling was done at the nodes.
  • There is no labelling at all between actions and events, just a small connector shape.

The combination of these two improvements means that 1) it is easier to read the graph as all the edges are labelled and the flow is oriented in a left-to-right fashion, and 2) the layout is more space efficient as the nodes connecting actions to events takes up alot of space when they include labelling. Now, we have only small connector shapes with no labelling.

I'll illustrate the improved decision tree in the context of a decision about how much nitrogen to apply to a crop per acre that involves calculating the payoffs you might expect if you get Good, Average, or Poor weather during the growing season. This is what such a decision tree looks like with the improvements mentioned above:

Nitrogen application decision tree

There are a couple of other aspects of this decision tree that are also noteworthy. First, the labels for each possible action (e.g., Nitrogen application amounts) includes the cost per acre of applying that amount of Nitrogen. One aspect of constructing a decision tree is computing the cost for each course of action. The second aspect to note is that the terminal nodes on our decision tree are often payoffs that involve multiplying an estimate of revenue by the probability of some event that significantly affects the payoff (e.g., the quality of the weather during the growing season).

I created the visualization for the nitrogen application decision using Graphviz. To do so I piped the recipe below into the graphviz program "dot". The recipe illustrates how to add comments to your dot file to make it easy to follow your recipe for rendering a graph shape. The recipe is also organized into logical sections to also make it easier to read.

/**
* @author Paul Meagher
* @modified Sept 3/2013
* @purpose Decision tree for nitrogen application decision
*/ 

digraph NitrogenDecision {

  // orient graph left to right (instead of the top to bottom default)
  rankdir=LR;
 
  // don't display any directional arrows on the edges 
  edge [dir=none];
  
  // labelled nodes will appear inside a box shape
  node [shape=box];  

  // small connector shape without labels between actions and events 
  Apply100Kg[shape=diamond,style=filled,label="",height=.1,width=.1];
  Apply160Kg[shape=diamond,style=filled,label="",height=.1,width=.1];
  Apply220Kg[shape=diamond,style=filled,label="",height=.1,width=.1];
  
  // labels for terminal nodes when applying 100 kg nitrogen
  GoodSeason100Kg[label="Payoff = 0.2 * $8000"];
  AveSeason100Kg[label="Payoff = 0.5 * $7000"];
  PoorSeason100Kg[label="Payoff = 0.3 * $6000"];  

  // labels for terminal nodes when applying 160 kg nitrogen
  GoodSeason160Kg[label="Payoff = 0.2 * $9000"];
  AveSeason160Kg[label="Payoff = 0.5 * $8000"];
  PoorSeason160Kg[label="Payoff = 0.3 * $7000"];  

  // labels for terminal nodes when applying 220 kg nitrogen
  GoodSeason220Kg[label="Payoff = 0.2 * $10000"];
  AveSeason220Kg[label="Payoff = 0.5 * $9000"];
  PoorSeason220Kg[label="Payoff = 0.3 * $8000"];  

  // define edges and edge labels for each action
  Decision -> Apply100Kg[label="Apply 100 kg N (-$40)"];
  Decision -> Apply160Kg[label="Apply 160 kg N (-$64)"];
  Decision -> Apply220Kg[label="Apply 220 kg N (-$88)"];

  // define edges and edge labels for each action + events combo
  Apply100Kg -> GoodSeason100Kg[label="Good Season ... P = 0.2"];
  Apply100Kg -> AveSeason100Kg[label="Ave. Season ... P = 0.5"];
  Apply100Kg -> PoorSeason100Kg[label="Poor Season ... P = 0.3"];
  Apply160Kg -> GoodSeason160Kg[label="Good Season ... P = 0.2"];
  Apply160Kg -> AveSeason160Kg[label="Ave. Season ... P = 0.5"];
  Apply160Kg -> PoorSeason160Kg[label="Poor Season ... P = 0.3"];
  Apply220Kg -> GoodSeason220Kg[label="Good Season ... P = 0.2"];
  Apply220Kg -> AveSeason220Kg[label="Ave. Season ... P = 0.5"];
  Apply220Kg -> PoorSeason220Kg[label="Poor Season ... P = 0.3"];

}

Figuring out how to render decision trees with labelled intermediate edges instead of labelled intermediate nodes was a big step in creating a decision tree format that I find is more workable. I'm not done yet, however, as I want to explore some other features of graphviz to add some more tweaks to my decision tree.

Permalink 

 Archive 
 

Categories


 Agriculture [71]
 Bayesian Inference [14]
 Books [15]
 Business Models [24]
 Causal Inference [2]
 Creativity [7]
 Decision Making [15]
 Decision Trees [8]
 Design [36]
 Eco-Green [4]
 Economics [11]
 Education [10]
 Energy [0]
 Entrepreneurship [58]
 Events [2]
 Farming [20]
 Finance [25]
 Future [15]
 Growth [18]
 Investing [24]
 Lean Startup [10]
 Leisure [5]
 Lens Model [9]
 Making [1]
 Management [9]
 Motivation [3]
 Nature [22]
 Patents & Trademarks [1]
 Permaculture [34]
 Psychology [1]
 Real Estate [2]
 Robots [1]
 Selling [11]
 Site News [14]
 Startups [12]
 Statistics [3]
 Systems Thinking [3]
 Trends [7]
 Useful Links [3]
 Valuation [1]
 Venture Capital [5]
 Video [2]
 Writing [2]