Addaly is in open beta. Things will change, and AI answers can be wrong — check anything that matters.

The Maths You Actually Need

Eight ideas that carry almost all the weight in machine learning.

Lesson 55 of 7610 min

Updating a rate as evidence arrives: the Beta distribution

A belief about a rate, as a curve

The last three lessons treated a rate, an accuracy or a failure probability, as a fixed unknown and built intervals around estimates of it. The Bayesian route treats the rate itself as uncertain and describes that uncertainty with a distribution over the interval from 0 to 1. The distribution that makes this easy is the Beta, written Beta(a, b), with two positive parameters.

The shapes worth knowing: Beta(1, 1) is flat, every rate equally plausible. Beta(2, 2) is a gentle hump at 0.5. Beta(50, 2) is a sharp peak near 0.96. The mean is always

mean of Beta(a, b) = a / (a + b)

and the peak sharpens as a + b grows.

The update is addition

Here is the fact that makes the Beta useful. If your belief about a rate is Beta(a, b) and you then observe k successes and m failures, your updated belief is

Beta(a + k, b + m)

That is the entire calculation. No integrals, no simulation. The parameters behave as counts: a is successes seen so far, b failures, and the prior Beta(a, b) is the statement "before this data, I had seen about a successes and b failures". Real or imagined, they add the same way.

Start flat, Beta(1, 1), observe 49 correct out of 50, and the posterior is Beta(50, 2), with mean 50/52 = 0.962 and a 95 per cent range from 0.896 to 0.995. Compare the Wilson interval from two lessons ago, 0.895 to 0.997: the two routes agree to the second decimal, as they generally do once the data outweigh the prior.

Start flat, observe 300 runs with no failures, and the posterior on the failure rate is Beta(1, 301), mean 1/302 = 0.33 per cent, 95 per cent upper bound 0.99 per cent. The rule of three, recovered exactly. The flat prior's one imaginary failure is what keeps the estimate off zero, and (k + 1)/(n + 2) as the mean after k of n is Laplace's rule of succession, two centuries old.

What you get that a confidence interval does not

The interval 0.896 to 0.995 above is a credible interval: there is, given the prior and the data, a 95 per cent probability that the rate lies inside it. That is the sentence everyone wants to say about a confidence interval and cannot. The Bayesian version licenses it, at the price of stating a prior. The price is real. Two people with different priors reach different posteriors from the same fifty items, and either can be asked to defend the choice. A confidence interval has no such argument attached, and also no such sentence.

Smoothing, which is the same thing

A ranking system estimates click-through rates. Item A has 1 click from 1 view; item B has 40 clicks from 100 views. By raw rate, A is at 100 per cent and wins. Nobody believes that, and the Beta says why. Use a prior of Beta(2, 8): ten pseudo-views at a 20 per cent rate, a modest belief about what items usually do.

A: (1 + 2) / (1 + 10)   = 3 / 11  = 0.273
B: (40 + 2) / (100 + 10) = 42 / 110 = 0.382

B wins. A's single view is nearly swamped by the ten imaginary ones; B's hundred real views hold their ground. As A accumulates views the prior fades, since its weight is a + b against the growing n. This is additive smoothing, and it is in every search engine, every recommender and every spam filter, usually without anyone calling it Bayesian.

Picking from uncertain rates

The Beta also gives the simplest decision rule that works for choosing between options with unknown rates. For each option, draw one random rate from its current Beta; pick the option whose draw is largest; observe the result; update that option's Beta. An option with little data has a wide Beta and is sometimes drawn high, so it gets tried; an option with much data and a low rate is almost never drawn high, so it is left alone. This is Thompson sampling, and it is a working A/B testing engine in a dozen lines:

python
import numpy as np
rng = np.random.default_rng(0)
succ, fail = np.ones(3), np.ones(3)          # Beta(1,1) for three options
for _ in range(1000):
    i = np.argmax(rng.beta(succ, fail))       # one draw per option
    reward = rng.random() < true_rates[i]
    succ[i] += reward; fail[i] += 1 - reward

Where the Beta is the wrong model

It describes a single fixed rate. If the rate differs by context, by user, by time of day, by input length, a single Beta averages over things that should be kept apart, and its narrow posterior expresses confidence about an average nobody experiences. The remedy is one Beta per context, or a model with the context as an input, which is the point at which this becomes machine learning.

And a strong wrong prior is slow to overcome. Beta(200, 800) claims a thousand prior observations; two hundred real successes in a row move its mean only from 0.20 to 0.33. State the prior in counts, and if you cannot defend the count, use a smaller one.

python
from scipy.stats import beta
beta(50, 2).ppf([0.025, 0.975])      # (0.896, 0.995)

The one thing to keep

A Beta(a, b) belief about a rate updates to Beta(a + k, b + m) after k successes and m failures, so the prior is just pseudo-counts that fade as data accumulate, which is why the same arithmetic gives credible intervals, click-rate smoothing and Thompson sampling.

Before you move on

A ranking system smooths click rates with a Beta(2, 8) prior. Item A has 1 click from 1 view; item B has 40 clicks from 100 views. Which ranks higher, and why?

Pick the one you would defend. Nobody sees your answer.

No ads. No data sale. No public scores on people. Ever.

© 2026 Addaly

Updating a rate as evidence arrives: the Beta distribution · The Maths You Actually Need · Addaly