Graphviz Example: decision tree

digraph DecisionTree {
rankdir=TB; // Top to Bottom layout
nodesep=0.5; // Horizontal spacing
ranksep=1.0; // Vertical spacing

// Root Node
node [shape=box, style=filled, color=lightblue]; // Decision nodes styling
"Is it raining?" [label="Is it raining?"];

// Level 1
node [shape=box, style=filled, color=lightyellow];
"Do you have an umbrella?" [label="Do you have an umbrella?"];

node [shape=ellipse, style=filled, color=lightgreen]; // Leaf nodes styling
"Take umbrella" [label="Take umbrella"];
"Don't go outside" [label="Don't go outside"];
"Enjoy your walk" [label="Enjoy your walk"];

// Edges
"Is it raining?" -> "Do you have an umbrella?" [label="Yes"];
"Is it raining?" -> "Enjoy your walk" [label="No"];

"Do you have an umbrella?" -> "Take umbrella" [label="Yes"];
"Do you have an umbrella?" -> "Don't go outside" [label="No"];

// Rank alignment
{ rank=same; "Take umbrella"; "Don't go outside"; }
}
DecisionTree Is it raining? Is it raining? Do you have an umbrella? Do you have an umbrella? Is it raining?->Do you have an umbrella? Yes Enjoy your walk Enjoy your walk Is it raining?->Enjoy your walk No Take umbrella Take umbrella Do you have an umbrella?->Take umbrella Yes Don't go outside Don't go outside Do you have an umbrella?->Don't go outside No