liveBook · Manning

Probability theory

As explained in Statistics Every Programmer Needs

Probability is a mathematical framework for assigning and analyzing the likelihood of uncertain events.

Probability quantifies uncertainty: it assigns a likelihood to an event so that risks, predictions, and decisions can be assessed systematically. It underpins statistical inference and models of uncertain outcomes. section 2.0 section 1.1.4

For equally likely outcomes, probability is the number of favorable outcomes divided by the total number of possible outcomes. Define the event before counting: a product malfunction, for example, can be the outcome of interest even though it is undesirable. Check both the definition of success and the denominator, especially when outcomes involve multiple dice or cards drawn without replacement. section 2.1

Choose a calculation that matches the event:

  • Use counting rules, combinations, or permutations to establish how many outcomes qualify and how many are possible. section 2.0
  • Multiply probabilities for independent events that must both occur; add probabilities for mutually exclusive alternatives when either can occur. section 3.2
  • Distinguish probability from odds: probability compares successes with all outcomes, while odds compare successes with failures. section 2.1.2

Count an event before calculating it

Two fair dice produce 6 × 6 = 36 ordered outcomes. If the first must show 1, 2, or 3 and the second must show 4, 5, or 6, there are 3 × 3 = 9 favorable outcomes. The probability is 9/36, or 25%. Treat (3, 4) and (4, 3) as different outcomes; only the first meets these conditions. section 3.2.3

>>> probability_heads = 1 / 2
>>> probability_heads_percent = probability_heads * 100
>>> print(f'The probability of success equals: '
      f'{probability_heads_percent}%')
The probability of success equals: 50.0%

This short Python calculation shows how a 1/2 probability becomes a displayed 50.0%. Multiplying by 100 changes its presentation, not the underlying likelihood. section 2.1.2

The framework extends beyond equally likely game outcomes. Random variables and probability distributions structure uncertain quantities; conditional probability addresses likelihood given information. In a decision tree, probabilities label uncertain branches alongside their payoffs. In Markov analysis, transition calculations can estimate the probabilities of reaching absorbing states. Interpret any result in light of how its outcomes and assumptions were specified. section 1.4.3 section 10.2 section 11.4.2

How Statistics Every Programmer Needs covers it

How deep it goes
Develops favorable-outcome calculations, odds, counting rules, and applied event problems, then extends to random variables, distributions, and conditional probability.
Examples
Works through coin flips, dice rolls, card selections, Python percentage calculations, and uncertain investment outcomes.
What it assumes
Starts with basic probability and introduces Python code progressively, while building toward counting methods and distributions.
What you can do after
Apply it to count event outcomes, calculate and present probabilities, and assess uncertain decision paths.
How it connects
Connects to statistical inference, counting rules, random variables, probability distributions, conditional probability, decision trees, and Markov analysis.

Also explained in

Compare how 16 books explain probability theory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.