liveBook · Manning

Log probability

As explained in Machine Learning Algorithms in Depth

A log likelihood is the logarithm of a model likelihood for observed data, commonly optimized instead of the likelihood itself.

A log probability is the logarithm of a probability assigned by a model. When the probability is assigned to observed data under model parameters θ, it is a log likelihood: log p(data | θ). Maximizing log likelihood is equivalent to minimizing its negative, called negative log likelihood (NLL). The same quantity can therefore serve as a training objective or as a score for how well an observation fits a trained model. section 5.4 section 11.1.1

In binary logistic regression, model parameters determine class probabilities. Training forms a log-likelihood objective for the labeled observations, changes its sign to obtain a loss, and differentiates that loss to update the parameters with stochastic gradient descent. Regularization can be added to control parameter size. This is an optimization use of log probability: seek parameters that assign greater likelihood to the observed labels. section 5.4

Log likelihood also supports a count-based derivation. For Bernoulli naive Bayes, word presence or absence supplies the observations. Maximizing a log-likelihood objective subject to class probabilities summing to one yields class-probability estimates from class counts; differentiating for the word parameters likewise yields ratios of counts. section 5.5

Scoring a time-series anomaly

Train a variational autoencoder on nonanomalous sensor signals. For each sensor, the model learns Gaussian likelihood parameters and reports log p(xᵢ | μᵢ, σᵢ) for an input xᵢ. Its objective maximizes log likelihood averaged over sensors while also shaping the latent space through KL divergence. At detection time, a drop in an input’s log likelihood can be thresholded to flag an anomaly. section 11.1.1

Figure 11.4 LSTM-VAE anomaly detection result
figure

The anomaly-detection result illustrates the drop in log likelihood used to set a detection threshold. section 11.1.1

How Machine Learning Algorithms in Depth covers it

How deep it goes
Derives optimization objectives and gradients for classifiers, then applies Gaussian log likelihood in an implemented anomaly detector.
Examples
Works through logistic regression, Bernoulli naive Bayes document classification, and an LSTM-VAE detecting anomalies in sensor time series.
What it assumes
Assumes familiarity with probabilities and gradients while developing log likelihood through classification and anomaly-detection objectives.
What you can do after
Build it from scratch as a logistic-regression loss, or apply it via Keras/TensorFlow to threshold anomalous sensor readings.
How it connects
Connects log likelihood to negative log likelihood, stochastic gradient descent, maximum likelihood estimation, Gaussian likelihood, and KL divergence.

Also explained in

Compare how 8 books explain log probability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Algorithms in Depth. The section links point to the parts of the book it draws on.