Explain Bayesian vs. frequentist thinking — when does each matter in ML?
Written by the mlprep team · Updated
Explain the difference between Bayesian and frequentist approaches to statistics. When would you use each in an ML engineering context, and what are the practical tradeoffs?
The core philosophical difference: frequentists treat probability as long-run frequency of events, while Bayesians treat probability as a degree of belief that gets updated with evidence.
Frequentist view#
- Parameters are fixed, unknown constants
- Probability = "if I repeated this experiment infinitely, what fraction of times would this happen?"
- A confidence interval means: "if I repeated this procedure, 95% of intervals would contain the true value"
- It does NOT mean "there's a 95% chance the true value is in this interval" (the true value either is or isn't — it's not random)
Bayesian view#
- Parameters have probability distributions reflecting uncertainty
- Start with a prior distribution P(θ) — what you believed before seeing data
- Update with data using Bayes' theorem: P(θ|data) ∝ P(data|θ) × P(θ)
- The posterior P(θ|data) represents your updated belief
- A 95% credible interval means exactly what you think: "given the data, there's a 95% probability the parameter is in this range"
Bayes' theorem in practice#
P(θ | data) = P(data | θ) × P(θ) / P(data)
posterior = likelihood × prior / normalizing constant
The prior encodes domain knowledge. The likelihood measures how well the data matches each possible parameter value. The posterior combines both.
When to use frequentist methods#
- A/B testing where you need pre-registered, auditable statistical tests with guaranteed error rates. Regulatory contexts (clinical trials, finance) often require frequentist guarantees.
- Large data where the prior is overwhelmed by the likelihood anyway — both approaches give nearly identical answers, and frequentist methods are computationally cheaper.
- Simple hypothesis tests where you just need a yes/no decision: is this effect real?
When to use Bayesian methods#
-
Small data where prior knowledge matters. If you've tested 100 similar features and most improved CTR by 1-3%, that's a strong prior for your next experiment. Bayesian reasoning formally incorporates this.
-
Uncertainty quantification in production. When a model predicts "70% probability of churn," you want to know how confident the model is in that 70%. Bayesian neural networks provide posterior predictive distributions — not just point predictions but distributions over predictions. High uncertainty → defer to human or fallback system.
-
Online learning where beliefs update continuously. Bayesian bandits (Thompson sampling) naturally balance exploration and exploitation: actions with uncertain reward get explored, actions with well-known reward get exploited.
-
Cold start problems. New users/items have no data. Bayesian priors let you start with population-level estimates and update as user-specific data arrives. This is hierarchical modeling — individual parameters are drawn from a population distribution.
Practical example: click-through rate estimation#
Frequentist: a button was clicked 3 out of 5 times. CTR = 0.6. Confidence interval with 5 observations is huge: [0.15, 0.95].
Bayesian: prior knowledge says most buttons have CTR between 0.01 and 0.10 (Beta(2, 20) prior). After observing 3/5 clicks: posterior is Beta(5, 22). Posterior mean = 0.19 — the prior pulls the estimate toward typical button behavior. With more data, the prior gets overwhelmed and both methods converge.
With 5 observations, the Bayesian estimate (0.19) is likely more accurate than the frequentist estimate (0.60) because it incorporates the knowledge that 60% CTR is unrealistic for most buttons.
Computational tradeoff#
Bayesian inference requires computing (or approximating) the posterior:
- Conjugate priors: closed-form (fast, limited model families)
- MCMC (Markov Chain Monte Carlo): general but slow, doesn't scale to millions of parameters
- Variational inference: approximate but scalable to large models
- MC Dropout: cheap Bayesian approximation for neural networks
For production ML at scale, full Bayesian inference is usually too expensive. Approximations (MC Dropout, ensemble methods as "poor man's Bayesian") are the pragmatic middle ground.
Interview red flags#
- Describing a frequentist 95% confidence interval as "a 95% chance the parameter is in this interval". That is the Bayesian credible interval's meaning.
- Treating the prior as arbitrary or something to hide, instead of stating it and checking sensitivity to it.
- Claiming one paradigm is always right rather than matching it to data size, regulation, and the decision being made.
- Not connecting Bayesian ideas to real ML practice, such as Thompson sampling or shrinkage for cold-start estimates.
You mentioned Thompson sampling for bandits. Walk me through how it works and why it's Bayesian — what advantage does it have over epsilon-greedy?
Thompson sampling is a Bayesian approach to the explore/exploit tradeoff in multi-armed bandits. Instead of choosing between exploration (random) and exploitation (best known), it naturally does both by sampling from posterior distributions.
How it works#
-
For each arm (action), maintain a posterior distribution over its reward rate. For binary outcomes (click/no-click), use a Beta distribution: Beta(successes + 1, failures + 1).
-
At each decision point: sample one value from each arm's posterior distribution.
-
Choose the arm with the highest sampled value.
-
Observe the outcome, update that arm's posterior.
import numpy as np
class ThompsonBandit:
def __init__(self, n_arms):
self.successes = np.ones(n_arms)
self.failures = np.ones(n_arms)
def select_arm(self):
samples = np.random.beta(self.successes, self.failures)
return np.argmax(samples)
def update(self, arm, reward):
if reward:
self.successes[arm] += 1
else:
self.failures[arm] += 1Why this is Bayesian: each arm's Beta distribution represents your current belief about its true reward rate. When you have little data, the posterior is wide (uncertain) — samples from it are highly variable, causing exploration. When you have lots of data, the posterior is narrow — samples are consistent, causing exploitation.
Advantage over epsilon-greedy#
Epsilon-greedy explores uniformly at random with probability ε, regardless of what you know. It wastes exploration budget on clearly bad arms and under-explores uncertain ones.
Thompson sampling explores proportional to the probability that each arm is optimal. An arm that could plausibly be the best (wide posterior overlapping with the current best) gets explored. An arm that's clearly bad (posterior far below others) is almost never sampled, even during "exploration."
Result: Thompson sampling converges to the best arm faster, accumulates less regret, and does so with zero hyperparameters (no ε to tune).
When it matters: content recommendation where you have many possible items and limited traffic. Epsilon-greedy wastes 10% of impressions on random garbage. Thompson sampling focuses exploration on genuinely promising options.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Frequentist = fixed parameters, probability as long-run frequency, guaranteed error rates. Bayesian = parameters have distributions, probability as belief, formally incorporates prior knowledge. Use frequentist for large-data hypothesis testing and regulated contexts. Use Bayesian for small data, uncertainty quantification, online learning (Thompson sampling), and cold start problems. At ML scale, approximate Bayesian methods (MC Dropout, ensembles) are the pragmatic middle ground.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you set a prior for a new ML model's performance when you have no historical data for that specific model but have results from similar models?
- Explain the difference between a confidence interval and a credible interval — and why a product manager would care about the difference.
- When would Bayesian model averaging be preferable to picking a single best model?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Walk me through how you'd design and analyze an A/B test
Which probability distributions matter most in ML, and when do you use each?
Why does the Central Limit Theorem matter for ML and statistics?
What is maximum likelihood estimation and why is it everywhere in ML?