โ† Back to DevOps & Cloud
DevOps & Cloud by @evgyur

decision-trees

Decision tree analysis for complex decision-making across all

0
Source Code

Decision Trees โ€” Structured Decision-Making

Decision tree analysis: a visual tool for making decisions with probabilities and expected value.

When to Use

โœ… Good for:

  • Business decisions (investments, hiring, product launches)
  • Personal choices (career, relocation, purchases)
  • Trading & investing (position sizing, entry/exit)
  • Operational decisions (expansion, outsourcing)
  • Any situation with measurable consequences

โŒ Not suitable for:

  • Decisions with true uncertainty (black swans)
  • Fast tactical choices
  • Purely emotional/ethical questions

Method

Decision tree = tree-like structure where:

  • Decision nodes (squares) โ€” your actions
  • Chance nodes (circles) โ€” random events
  • End nodes (triangles) โ€” final outcomes

Process:

  1. Define options โ€” all possible actions
  2. Define outcomes โ€” what can happen after each action
  3. Estimate probabilities โ€” how likely is each outcome (0-100%)
  4. Estimate values โ€” utility/reward for each outcome (money, points, utility units)
  5. Calculate EV โ€” expected value = ฮฃ (probability ร— value)
  6. Choose โ€” option with highest EV

Formula

EV = ฮฃ (probability_i ร— value_i)

Example:

  • Outcome A: 70% probability, +$100 โ†’ 0.7 ร— 100 = $70
  • Outcome B: 30% probability, -$50 โ†’ 0.3 ร— (-50) = -$15
  • EV = $70 + (-$15) = $55

Classic Example (from Wikipedia)

Decision: Go to party or stay home?

Estimates:

  • Party: +9 utility (fun)
  • Home: +3 utility (comfort)
  • Carrying jacket unnecessarily: -2 utility
  • Being cold: -10 utility
  • Probability cold: 70%
  • Probability warm: 30%

Tree:

Decision
โ”œโ”€ Go to party
โ”‚  โ”œโ”€ Take jacket
โ”‚  โ”‚  โ”œโ”€ Cold (70%) โ†’ 9 utility (party)
โ”‚  โ”‚  โ””โ”€ Warm (30%) โ†’ 9 - 2 = 7 utility (carried unnecessarily)
โ”‚  โ”‚  EV = 0.7 ร— 9 + 0.3 ร— 7 = 8.4
โ”‚  โ””โ”€ Don't take jacket
โ”‚     โ”œโ”€ Cold (70%) โ†’ 9 - 10 = -1 utility (froze)
โ”‚     โ””โ”€ Warm (30%) โ†’ 9 utility (perfect)
โ”‚     EV = 0.7 ร— (-1) + 0.3 ร— 9 = 2.0
โ””โ”€ Stay home
   โ””โ”€ EV = 3.0 (always)

Conclusion: Go and take jacket (EV = 8.4) > stay home (EV = 3.0) > go without jacket (EV = 2.0)

Business Example

Decision: Launch new product?

Estimates:

  • Success probability: 40%
  • Failure probability: 60%
  • Profit if success: $500K
  • Loss if failure: $200K
  • Don't launch: $0

Tree:

Launch product
โ”œโ”€ Success (40%) โ†’ +$500K
โ””โ”€ Failure (60%) โ†’ -$200K

EV = (0.4 ร— 500K) + (0.6 ร— -200K) = 200K - 120K = +$80K

Don't launch
โ””โ”€ EV = $0

Conclusion: Launch (EV = +$80K) is better than not launching ($0).

Trading Example

Decision: Enter position or wait?

Estimates:

  • Probability of rise: 60%
  • Probability of fall: 40%
  • Position size: $1000
  • Target: +10% ($100 profit)
  • Stop-loss: -5% ($50 loss)

Tree:

Enter position
โ”œโ”€ Rise (60%) โ†’ +$100
โ””โ”€ Fall (40%) โ†’ -$50

EV = (0.6 ร— 100) + (0.4 ร— -50) = 60 - 20 = +$40

Wait
โ””โ”€ No position โ†’ $0

EV = $0

Conclusion: Entering position has positive EV (+$40), better than waiting ($0).

Method Limitations

โš ๏ธ Critical points:

  1. Subjective estimates โ€” probabilities often "finger in the air"
  2. Doesn't account for risk appetite โ€” ignores psychology (loss aversion)
  3. Simplified model โ€” reality is more complex
  4. Unstable โ€” small data changes can drastically alter the tree
  5. May be inaccurate โ€” other methods exist that are more precise (random forests)

But: The method is valuable for structuring thinking, even if numbers are approximate.

User Workflow

1. Structuring

Ask:

  • What are the action options?
  • What are possible outcomes?
  • What are values/utility for each outcome?
  • How do we measure value? (money, utility units, happiness points)

2. Probability Estimation

Help estimate through:

  • Historical data (if available)
  • Comparable situations
  • Expert judgment (user experience)
  • Subjective assessment (if no data)

3. Visualization

Draw tree in markdown:

Decision
โ”œโ”€ Option A
โ”‚  โ”œโ”€ Outcome A1 (X%) โ†’ Value Y
โ”‚  โ””โ”€ Outcome A2 (Z%) โ†’ Value W
โ””โ”€ Option B
   โ””โ”€ Outcome B1 (100%) โ†’ Value V

4. EV Calculation

For each option:

EV_A = (X% ร— Y) + (Z% ร— W)
EV_B = V

5. Recommendation

Option with highest EV = best choice (rationally).

But add context:

  • Risk tolerance (can user handle worst case)
  • Time horizon (when is result needed)
  • Other factors (reputational risk, emotions, ethics)

Application Examples by Domain

Trading & Investing

Position Sizing:

  • Options: 5%, 10%, 20% of capital
  • Outcomes: Profit/loss with different probabilities
  • Value: Absolute profit in $

Entry Timing:

  • Options: Enter now, wait for -5%, wait for -10%
  • Outcomes: Price goes up/down
  • Value: Opportunity cost vs better entry price

Business Strategy

Product Launch:

  • Options: Launch / don't launch
  • Outcomes: Success / failure
  • Value: Revenue, market share, costs

Hiring Decision:

  • Options: Hire candidate A / candidate B / don't hire
  • Outcomes: Successful onboarding / quit after X months
  • Value: Productivity, costs, opportunity cost

Personal Decisions

Career Change:

  • Options: Stay / change job / start business
  • Outcomes: Success / failure in new role
  • Value: Salary, satisfaction, growth, risk

Real Estate:

  • Options: Buy house A / house B / continue renting
  • Outcomes: Price increase / decrease / personal situation changes
  • Value: Net worth, monthly costs, quality of life

Operations

Capacity Planning:

  • Options: Expand production / outsource / status quo
  • Outcomes: Demand increases / decreases
  • Value: Profit, utilization, fixed costs

Vendor Selection:

  • Options: Vendor A / Vendor B / in-house
  • Outcomes: Quality, reliability, failures
  • Value: Total cost of ownership

Calculator Script

Use scripts/decision_tree.py for automated EV calculations:

python3 scripts/decision_tree.py --interactive

Or via JSON:

python3 scripts/decision_tree.py --json tree.json

JSON format:

{
  "decision": "Launch product?",
  "options": [
    {
      "name": "Launch",
      "outcomes": [
        {"name": "Success", "probability": 0.4, "value": 500000},
        {"name": "Failure", "probability": 0.6, "value": -200000}
      ]
    },
    {
      "name": "Don't launch",
      "outcomes": [
        {"name": "Status quo", "probability": 1.0, "value": 0}
      ]
    }
  ]
}

Output:

๐Ÿ“Š Decision Tree Analysis

Decision: Launch product?

Option 1: Launch
  โ””โ”€ EV = $80,000.00
     โ”œโ”€ Success (40.0%) โ†’ +$500,000.00
     โ””โ”€ Failure (60.0%) โ†’ -$200,000.00

Option 2: Don't launch
  โ””โ”€ EV = $0.00
     โ””โ”€ Status quo (100.0%) โ†’ $0.00

โœ… Recommendation: Launch (EV: $80,000.00)

Final Checklist

Before giving recommendation, ensure:

  • โœ… All options covered
  • โœ… Probabilities sum to 100% for each branch
  • โœ… Values are realistic (not fantasies)
  • โœ… Worst case scenario is clear to user
  • โœ… Risk/reward ratio is explicit
  • โœ… Method limitations mentioned
  • โœ… Qualitative context added (not just EV)

Method Advantages

โœ… Simple โ€” people understand trees intuitively โœ… Visual โ€” clear structure โœ… Works with little data โ€” can use expert estimates โœ… White box โ€” transparent logic โœ… Worst/best case โ€” extreme scenarios visible โœ… Multiple decision-makers โ€” can account for different interests

Method Disadvantages

โŒ Unstable โ€” small data changes โ†’ large tree changes โŒ Inaccurate โ€” often more precise methods exist โŒ Subjective โ€” probability estimates "from the head" โŒ Complex โ€” becomes unwieldy with many outcomes โŒ Doesn't account for risk preference โ€” assumes risk neutrality

Important

The method is valuable for structuring thinking, but numbers are often taken from thin air.

What matters more is the process โ€” forcing yourself to think through all branches and explicitly evaluate consequences.

Don't sell the decision as "scientifically proven" โ€” it's just a framework for conscious choice.

Further Reading

  • Decision trees in operations research
  • Influence diagrams (more compact for complex decisions)
  • Utility functions (accounting for risk aversion)
  • Monte Carlo simulation (for greater accuracy)
  • Real options analysis (for strategic decisions)