Posted on September 12, 2013 @ 08:14:00 AM by Paul Meagher
In the last few blogs I've discussed using Graphviz to generate nice looking decision trees. Sometimes, however, it is difficult to get exactly what you want out of Graphviz because it is designed to generate graphs dynamically (easy to change values/labels and generate a new graph) rather than uniquely crafted one-offs. I decided to explore other alternatives to creating decision tree graphs and, to make a long story short, I have decided that a programming language called "Processing" (see http://www.processing.org website) offers the flexibility I need along with many other benefits. Processing opens up the possibilities for visualizing decisions exponentially because it can be used to create multimedia output, including graphs, on a huge range of devices (e.g., desktop browers, mobile devices, embedded devices). It is also a very elegant language and has a javascript+html5 implementation that makes executing "sketches" (e.g., the processing term for a program) in a webpage a breeze (the output of which can be static, animated, sonically enhanced, etc...). It also has an excellent development environment bundled with it and a large opensouce developer community. Finally, there are some extremely well written books on learning and using the language. The one to start with is by the language's authors:
Processing: A Programming Handbook
for Visual Designers and Artists
Casey Reas and Ben Fry (Foreword by John Maeda).
Published August 2007, MIT Press. 736 pages. Hardcover.
To give you a flavor of the language I'll offer up a couple of processing sketches from the book above. I was looking for some code that would get me started on drawing a tree and found this code (p. 202) for drawing a T.
The code above generates a simple tree structure that could be the starting point for a decision tree:
Cool! By making a few modifications to this program (e.g., adding recursive calls to the drawT function) a fractal tree can be generated with the following code:
Here is the output that the sketch above generates:
This, of course, is not a full-bodied decision tree but it gives us some insight into how the skeleton of a simple binary decision tree might be created - by calling a drawT function multiple times with the appropriate positional parameters. I'd prefer a left-to-right layout rather than a bottom-to-top layout so that connections can be labelled easier.
|