Probability for ML
Theme
Palette
Download
Caption (tap to copy)
📖 Deep dive (full written explanation)
This cover sets up the argument that probability is not optional polish on top of ML — it is structural. The hook is that without a measure of uncertainty you literally cannot distinguish a model that is confident for good reasons from one that simply got lucky on the test set. Measurement of uncertainty is what separates a trustworthy system from a fragile one.
The post answers 'why,' which is the bridge between the conceptual first post and the mechanical third. Loss functions, model comparison, and decision-making under risk are all probability in disguise, and seeing that unifies a lot of otherwise scattered practice.
Point estimates hide the single most important piece of information: how much to trust them. Reporting that a price will be two hundred dollars sounds precise, but it is silent about risk. The same point estimate with a tight spread versus a huge spread describes two completely different situations, and only a distribution captures the difference.
In production ML this matters constantly. A demand forecast, a credit score, a medical risk — each is far more useful with its uncertainty attached. Stakeholders who only ever see the central number end up over-trusting predictions precisely when the model was least sure, which is exactly when caution was warranted.
Loss functions are where probability quietly drives the entire training process. Cross-entropy, the standard classification loss, is the negative log-likelihood of the observed labels under the model's predicted distribution. Minimizing it is mathematically identical to maximizing the probability the model assigns to the correct answers — training is probability maximization wearing an optimization costume.
Understanding this demystifies why the loss looks the way it does. The logarithm is there because we work in log-space for numerical stability, and the negative sign is there because optimizers minimize while we want to maximize likelihood. Once you see the loss as a likelihood, the otherwise arbitrary formula becomes the obvious thing to write down.
This snippet strips cross-entropy down to its essence so the connection to probability is undeniable. For each example, the model assigns some probability to the correct class; the loss penalizes that probability through its negative logarithm. High probability on the truth means a small log penalty; low probability means a large one. Averaging over examples gives the batch loss.
The code is deliberately framework-free so nothing is hidden. In real training you would use a library's cross-entropy and feed it logits, but the three lines here show that there is no magic: the loss is just 'how surprised was the model by the correct answers,' measured in log-probability. Running it and seeing 0.339 makes the abstraction tangible.
Calibration is the property most people assume their model has and most models lack. A calibrated model's stated probabilities match reality: among all the predictions it tags as 0.8 confident, about 80% are actually correct. Crucially, accuracy alone cannot detect a calibration problem — a model can be highly accurate yet systematically overconfident.
This is not academic. In medicine, finance, and safety-critical systems, the difference between a true 0.8 and a claimed-but-false 0.8 can be the difference between a sound decision and a harmful one. Calibration is what lets you take a probability at face value, which is the entire point of producing probabilities instead of bare labels.
The calibration bar chart visualizes overconfidence concretely. For each confidence bucket — predictions the model claimed were 0.6, 0.8, 0.9 likely — we plot the actual observed accuracy. A perfectly calibrated model would have bars matching the bucket labels. Here the higher buckets fall short of their claims, the signature of an overconfident model.
This kind of reliability diagram is the standard diagnostic tool. You bin predictions by stated confidence, measure the real hit rate in each bin, and compare. Gaps between claimed and observed confidence tell you exactly where and how badly the model is miscalibrated, which then guides the fix in the final slide.
Decisions, not predictions, are the real product of most ML systems, and good decisions require probabilities multiplied by costs. The expected value of an action is the sum over outcomes of probability times payoff. A small chance of a catastrophic loss can outweigh a large chance of a trivial gain — but you can only compute that trade-off if your probabilities are trustworthy.
Without calibrated probabilities you are reduced to hand-tuning thresholds and hoping. With them, you can set decision boundaries that optimize for the actual costs of false positives versus false negatives, which differ enormously between, say, spam filtering and cancer screening. Probability is what turns a prediction into a principled action.
This comparison clarifies why a raw model score is not interchangeable with a probability. A raw score lives on an arbitrary scale, is not comparable across different models, and gives you no principled way to set a threshold. A calibrated probability lives on the universal 0-to-1 scale, is comparable, and plugs directly into expected-value calculations.
The practical lesson is to resist the temptation to threshold raw scores directly in high-stakes settings. Two models might both output 'scores,' but a 0.7 from one and a 0.7 from another can mean entirely different things until both are calibrated to real probabilities. Calibration is the common currency that makes scores meaningful and combinable.
These four use cases show uncertainty earning its keep in production. When confidence is low you can route a case to a human reviewer instead of guessing. You can let the model abstain rather than make a confident wrong call. You can combine multiple models weighted by their confidence. And a sudden drop in average confidence is an early warning that the input distribution has drifted.
Each of these is impossible with bare labels and trivial with probabilities. This is the concrete payoff of all the conceptual work: uncertainty is not a number to admire, it is an actionable signal that makes systems safer, cheaper to operate, and easier to monitor over time.
The pipeline diagram captures the operational loop that uncertainty enables. The model predicts a distribution, a downstream step assesses how confident that distribution is, and based on the confidence the system either acts automatically or defers to a human. This three-stage pattern is the backbone of responsible ML deployment.
What makes the loop possible is that the prediction is a distribution, not a point. The 'assess' stage has something to measure, and the 'act or defer' stage has a principled basis for routing. Strip out the probability and the loop collapses into blind automation with no off-ramp when the model is unsure.
The closing mistake is the most important caveat in the whole post: raw softmax outputs from deep networks are not well-calibrated probabilities. Modern neural nets are notoriously overconfident, routinely emitting 0.99 for predictions that are wrong far more than 1% of the time. Treating these raw outputs as real probabilities for decisions is a common and costly error.
The fix is post-hoc calibration. Techniques like temperature scaling and Platt scaling adjust the outputs on a held-out set so the stated probabilities line up with observed accuracy. The takeaway is to never trust softmax confidence for high-stakes decisions until you have verified or corrected its calibration — which the mistakes post revisits in detail.
This teaser hands off to the mechanics post, where we open the engine and work through conditional probability, Bayes' rule, independence, and the distributions ML actually uses. Having argued why probability matters, the next post shows precisely how it operates.
The ordering is intentional: motivation first, machinery second. Now that you believe probability is worth understanding deeply, the formulas in the next post arrive as answers to questions you already care about rather than as abstract definitions.