{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"beta-distributions-and-updating-a-rate","title":"Updating a rate as evidence arrives: the Beta distribution","url":"https://addaly.com/learn/maths-you-need/beta-distributions-and-updating-a-rate","position":55,"of":76,"minutes":10,"answer":"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.","keyIdea":"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."},"body":{"format":"markdown","text":"## A belief about a rate, as a curve\n\nThe 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.\n\nThe 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\n\n```\nmean of Beta(a, b) = a / (a + b)\n```\n\nand the peak sharpens as `a + b` grows.\n\n## The update is addition\n\nHere 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\n\n```\nBeta(a + k, b + m)\n```\n\nThat 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.\n\nStart 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.\n\nStart 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.\n\n## What you get that a confidence interval does not\n\nThe 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.\n\n## Smoothing, which is the same thing\n\nA 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.\n\n```\nA: (1 + 2) / (1 + 10)   = 3 / 11  = 0.273\nB: (40 + 2) / (100 + 10) = 42 / 110 = 0.382\n```\n\nB 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.\n\n## Picking from uncertain rates\n\nThe 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:\n\n```python\nimport numpy as np\nrng = np.random.default_rng(0)\nsucc, fail = np.ones(3), np.ones(3)          # Beta(1,1) for three options\nfor _ in range(1000):\n    i = np.argmax(rng.beta(succ, fail))       # one draw per option\n    reward = rng.random() < true_rates[i]\n    succ[i] += reward; fail[i] += 1 - reward\n```\n\n## Where the Beta is the wrong model\n\nIt 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.\n\nAnd 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.\n\n```python\nfrom scipy.stats import beta\nbeta(50, 2).ppf([0.025, 0.975])      # (0.896, 0.995)\n```"},"check":{"question":"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?","options":[{"text":"A, because its observed rate is 100 per cent against B's 40 per cent.","correct":false,"tempting":"Ignores the prior entirely; the whole point of the pseudo-counts is that one view cannot establish a rate."},{"text":"They tie, because the prior overrides whatever the data say.","correct":false,"tempting":"A prior of ten pseudo-views is easily outweighed by a hundred real ones; it dominates only where the data are thin, as for A."},{"text":"A, because fewer views means a tighter estimate.","correct":false,"tempting":"Backwards: fewer observations mean a wider posterior, and the prior pulls a thin estimate toward its own mean."},{"text":"B, at about 38 per cent against A’s smoothed 27.","correct":true}]},"prev":{"slug":"the-rule-of-three","title":"Zero failures in 300 tries, and what that does not prove","url":"https://addaly.com/learn/maths-you-need/the-rule-of-three"},"next":{"slug":"maximum-a-posteriori-and-regularisation","title":"Regularisation is a prior: L2, L1 and the diamond","url":"https://addaly.com/learn/maths-you-need/maximum-a-posteriori-and-regularisation"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Updating a rate as evidence arrives: the Beta distribution', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/beta-distributions-and-updating-a-rate (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Updating a rate as evidence arrives: the Beta distribution","courseTitle":"The Maths You Actually Need","module":{"index":6,"slug":"estimation-from-samples","title":"Estimation: from a sample to a number you can trust"},"answer":null,"keyIdea":"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.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"a-belief-about-a-rate-as-a-curve","runs":[{"text":"A belief about a rate, as a curve"}]},{"t":"p","runs":[{"text":"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 "},{"text":"Beta","b":true},{"text":", written "},{"text":"Beta(a, b)","code":true},{"text":", with two positive parameters."}]},{"t":"p","runs":[{"text":"The shapes worth knowing: "},{"text":"Beta(1, 1)","code":true},{"text":" is flat, every rate equally plausible. "},{"text":"Beta(2, 2)","code":true},{"text":" is a gentle hump at 0.5. "},{"text":"Beta(50, 2)","code":true},{"text":" is a sharp peak near 0.96. The mean is always"}]},{"t":"code","lang":"","label":"Text","text":"mean of Beta(a, b) = a / (a + b)"},{"t":"p","runs":[{"text":"and the peak sharpens as "},{"text":"a + b","code":true},{"text":" grows."}]},{"t":"h2","id":"the-update-is-addition","runs":[{"text":"The update is addition"}]},{"t":"p","runs":[{"text":"Here is the fact that makes the Beta useful. If your belief about a rate is "},{"text":"Beta(a, b)","code":true},{"text":" and you then observe "},{"text":"k","code":true},{"text":" successes and "},{"text":"m","code":true},{"text":" failures, your updated belief is"}]},{"t":"code","lang":"","label":"Text","text":"Beta(a + k, b + m)"},{"t":"p","runs":[{"text":"That is the entire calculation. No integrals, no simulation. The parameters behave as "},{"text":"counts","b":true},{"text":": "},{"text":"a","code":true},{"text":" is successes seen so far, "},{"text":"b","code":true},{"text":" failures, and the prior "},{"text":"Beta(a, b)","code":true},{"text":" is the statement “before this data, I had seen about "},{"text":"a","code":true},{"text":" successes and "},{"text":"b","code":true},{"text":" failures”. Real or imagined, they add the same way."}]},{"t":"p","runs":[{"text":"Start flat, "},{"text":"Beta(1, 1)","code":true},{"text":", observe 49 correct out of 50, and the posterior is "},{"text":"Beta(50, 2)","code":true},{"text":", with mean "},{"text":"50/52 = 0.962","code":true},{"text":" 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."}]},{"t":"p","runs":[{"text":"Start flat, observe 300 runs with no failures, and the posterior on the "},{"text":"failure","i":true},{"text":" rate is "},{"text":"Beta(1, 301)","code":true},{"text":", mean "},{"text":"1/302 = 0.33","code":true},{"text":" 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 "},{"text":"(k + 1)/(n + 2)","code":true},{"text":" as the mean after "},{"text":"k","code":true},{"text":" of "},{"text":"n","code":true},{"text":" is Laplace’s rule of succession, two centuries old."}]},{"t":"h2","id":"what-you-get-that-a-confidence-interval-does-not","runs":[{"text":"What you get that a confidence interval does not"}]},{"t":"p","runs":[{"text":"The interval "},{"text":"0.896 to 0.995","code":true},{"text":" above is a "},{"text":"credible interval","b":true},{"text":": 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."}]},{"t":"h2","id":"smoothing-which-is-the-same-thing","runs":[{"text":"Smoothing, which is the same thing"}]},{"t":"p","runs":[{"text":"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 "},{"text":"Beta(2, 8)","code":true},{"text":": ten pseudo-views at a 20 per cent rate, a modest belief about what items usually do."}]},{"t":"code","lang":"","label":"Text","text":"A: (1 + 2) / (1 + 10)   = 3 / 11  = 0.273\nB: (40 + 2) / (100 + 10) = 42 / 110 = 0.382"},{"t":"p","runs":[{"text":"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 "},{"text":"a + b","code":true},{"text":" against the growing "},{"text":"n","code":true},{"text":". This is additive smoothing, and it is in every search engine, every recommender and every spam filter, usually without anyone calling it Bayesian."}]},{"t":"h2","id":"picking-from-uncertain-rates","runs":[{"text":"Picking from uncertain rates"}]},{"t":"p","runs":[{"text":"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:"}]},{"t":"code","lang":"python","label":"Python","text":"import numpy as np\nrng = np.random.default_rng(0)\nsucc, fail = np.ones(3), np.ones(3)          # Beta(1,1) for three options\nfor _ in range(1000):\n    i = np.argmax(rng.beta(succ, fail))       # one draw per option\n    reward = rng.random() < true_rates[i]\n    succ[i] += reward; fail[i] += 1 - reward"},{"t":"h2","id":"where-the-beta-is-the-wrong-model","runs":[{"text":"Where the Beta is the wrong model"}]},{"t":"p","runs":[{"text":"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."}]},{"t":"p","runs":[{"text":"And a strong wrong prior is slow to overcome. "},{"text":"Beta(200, 800)","code":true},{"text":" 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."}]},{"t":"code","lang":"python","label":"Python","text":"from scipy.stats import beta\nbeta(50, 2).ppf([0.025, 0.975])      # (0.896, 0.995)"}],"check":{"question":[{"text":"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?"}],"options":[{"text":[{"text":"A, because its observed rate is 100 per cent against B’s 40 per cent."}],"correct":false,"tempting":[{"text":"Ignores the prior entirely; the whole point of the pseudo-counts is that one view cannot establish a rate."}]},{"text":[{"text":"They tie, because the prior overrides whatever the data say."}],"correct":false,"tempting":[{"text":"A prior of ten pseudo-views is easily outweighed by a hundred real ones; it dominates only where the data are thin, as for A."}]},{"text":[{"text":"A, because fewer views means a tighter estimate."}],"correct":false,"tempting":[{"text":"Backwards: fewer observations mean a wider posterior, and the prior pulls a thin estimate toward its own mean."}]},{"text":[{"text":"B, at about 38 per cent against A’s smoothed 27."}],"correct":true,"tempting":null}],"order":[0,1,2,3],"why":null},"prev":{"slug":"the-rule-of-three","title":"Zero failures in 300 tries, and what that does not prove","minutes":8},"next":{"slug":"maximum-a-posteriori-and-regularisation","title":"Regularisation is a prior: L2, L1 and the diamond","minutes":10}}}