Thursday, December 19, 2013
Tikz: simple decision tree (or CART tree) example
I created the above diagram of a decision tree using the tikz package for LaTeX. It took me a while to find a simple, clear way to produce a decision tree. This is the code I used:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newdimen\nodeDist
\nodeDist=35mm
\begin{document}
\begin{tikzpicture}[
node/.style={%
draw,
rectangle,
},
]
\node [node] (A) {IDS $>$ 13.5?};
\path (A) ++(-135:\nodeDist) node [node] (B) {exit 1};
\path (A) ++(-45:\nodeDist) node [node] (C) {LCIanx $>$ 0.3604?};
\path (C) ++(-135:\nodeDist) node [node] (D) {exit 2};
\path (C) ++(-45:\nodeDist) node [node] (E) {exit 3};
\draw (A) -- (B) node [left,pos=0.25] {no}(A);
\draw (A) -- (C) node [right,pos=0.25] {yes}(A);
\draw (C) -- (D) node [left,pos=0.25] {no}(A);
\draw (C) -- (E) node [right,pos=0.25] {yes}(A);
\end{tikzpicture}
\end{document}
Subscribe to:
Post Comments (Atom)
Very useful. Thank you!
ReplyDeleteThank you very much for sharing!
ReplyDeleteThank you sooooo much! I've been search for this for a long time. This is exactly what I need to produce a simple decision tree.
ReplyDeleteAwesome! Thank you
ReplyDeleteExcellent!. Thank you so much.
ReplyDelete