Guide

A model that outputs 0.8 for "fraud" is making a probability claim. Cross-entropy loss, softmax, temperature sampling and confidence intervals all come from a small set of ideas: random variables, likelihood, Bayes and information. Learn them and the losses in training code stop looking like arbitrary formulas.

Training works like this. You define a probabilistic model of the labels, turn its likelihood into a loss, differentiate that loss with calculus, and descend with optimization. The concepts below cover the probability half of that story.

Every number a model prints is a guess with uncertainty attached. These ideas tell you where the guess comes from and how much weight it deserves. They also answer practical questions. Is a 1-point gain real? Does a positive test mean the condition is likely? Why did the team choose this loss?

Concepts in this section

Read them in order. The first two give you the vocabulary. The rest use it.

StepConceptWhat it answers
1Random variables and distributionsWhat is a probability distribution, and what do expectation and variance measure?
2Conditional probability and BayesHow should a test result change your belief?
3Maximum likelihoodWhy do squared error and cross-entropy show up as losses?
4Softmax and temperatureHow do raw scores become probabilities, and what does temperature change?
5Entropy and cross-entropyHow do you measure surprise, and what is perplexity?
6Uncertainty and sample sizeHow sure can you be about a metric from a finite test set?

Common mistakes

  • Reading accuracy as the chance a positive result is right. The base rate changes what a positive means. A 99%-accurate test on a 1% condition gives a positive result that is right only about 17% of the time.
  • Reporting a metric with no sample size. A small eval set can swing by more than the gain you are celebrating.
  • Treating a loss as arbitrary. Most standard losses are maximum likelihood under a specific assumption about the data.
  • Multiplying small probabilities directly. Long products underflow to zero. Work in logs, where products become sums.
  • Swapping the two directions of a conditional. P(positive test | sick) and P(sick | positive test) are different numbers.

Key takeaways

  • Most supervised outputs are a Bernoulli, categorical or Gaussian distribution.
  • Bayes' rule updates a prior with evidence. Base rates matter as much as accuracy.
  • Squared error is maximum likelihood under Gaussian noise. Cross-entropy is maximum likelihood for categorical outputs.
  • Softmax turns logits into probabilities, and temperature sharpens or flattens them.
  • Report eval metrics with an interval or the sample size.

Further learning

Seeing Theory (Brown University) has interactive visuals for distributions, conditional probability and Bayes. StatQuest with Josh Starmer is a good companion. Mathematics for Machine Learning covers the math formally. Think Stats (Allen Downey) is short and code-first.