Naive Bayes and Probabilistic Classification
Learning objectives
- State Bayes' rule for a classifier and say what the prior, the likelihood and the evidence each contribute
- Fit Gaussian naive Bayes to Ogbon-1's gamma ray and density and explain why its curves of equal density are upright ellipses
- Compute a sample's posterior by hand from the log prior and the log density of each log, and say why the 2Ο of each density cancels
- Explain why moving a prior moves the boundary yet changes few calls on Ogbon-1
One Bell Curve per Log
Naive Bayes calls a sample the class with the largest prior times likelihood, and the naive model writes the likelihood as one bell curve per log, as if the logs were independent within each class. Its curves of equal density are ellipses with upright axes. On Ogbon-1's gamma ray and density it finds the geology, shale high in gamma ray and limestone the densest and cleanest rock in the well, and with the samples' own priors it calls 0.998 of the well's 1201 samples right. Moving the limestone prior from 0.01 to 0.99 moves the boundary, yet the samples called right go only from 1198 to 1199: a prior decides only where the likelihoods are close.
The Data
The figure reads Ogbon-1, the Petrophysics book's well, as the book's own learning set holds it: 1201 samples from 5800 ft to 6400 ft every 0.5 ft, its gamma ray in API and its bulk density in g/cc as the book's own tool model records them. The class of each sample is the generator's lithology, read from the bed table: 429 samples of shale, 616 of sandstone and 156 of limestone. The whole set is synthetic, which is why every number below can be checked.
Bayes' Rule
For a sample with logs , Bayes' rule gives the posterior of rock as its prior times its likelihood , over the evidence . The evidence is the same for every rock, so the call is the rock with the largest prior times likelihood. The prior says how common a rock is before the logs are read; the likelihood says how well the rock explains the logs; the posterior is the share each rock earns.
The Naive Likelihood
Gaussian naive Bayes models each log within each rock as a normal distribution with the rock's own mean and variance, and multiplies them: . On Ogbon-1 shale sits at 114.6 API and 2.307 g/cc, sandstone at 29.0 API and 2.269 g/cc, and limestone at 21.9 API and 2.555 g/cc. The standard deviations are 8.1 API and 0.025 g/cc for shale, 10.4 API and 0.065 g/cc for sandstone, 7.7 API and 0.025 g/cc for limestone. A product of one curve per log has no term that ties the logs together, so its ellipses cannot lean. Within the sandstone gamma ray and density correlate at 0.571, the shalier sand the denser, and the sandstone cloud leans; its ellipse stands upright across it. That is the naive assumption, and Section 6.2 shows where it costs.
The Sum, Term by Term
Products of small densities underflow, so the model adds logarithms. Each rock's sum is its log prior plus the log density of each log,
and the posterior is each sum's exponential over the total. The figure's probe starts at 6117.5 ft, a limestone sample at the edge of a bed, where the tool averages the limestone with the rock above it. There sandstone sums to β13.76, limestone to β15.73 and shale to β57.51, so sandstone takes the posterior 0.878 and limestone 0.122: the sample is called sandstone. Each density carries the same β0.919, minus half the log of 2Ο, in every rock's every term, so it cancels in the shares and could be dropped without changing a call. The variances do not cancel: a narrow curve is taller at its mean, and at its own mean limestone's density curve reaches a log density of 2.76 against sandstone's 1.82.
Priors Move the Boundary
With the samples' own priors, shale 0.357, sandstone 0.513 and limestone 0.130, limestone begins at 2.474 g/cc at its own mean gamma ray. Make limestone rare, a prior of 0.01, and it begins at 2.490 g/cc; make it common, 0.99, and it begins at 2.441 g/cc. The probe is called limestone once the prior reaches 0.52, at a posterior of 0.503: the likelihoods did not change, only the weight on them. Yet across the whole range the samples called right go only from 1198 to 1199 of the 1201. The rocks sit far apart on the crossplot, so for almost every sample one rock's likelihood beats the others' by many powers of ten, and a prior moves the sum by its logarithm, a few units at most.
Where It Misses
With the samples' priors the model calls three samples wrong, 1.5 ft of the well: limestone at 6040.0 ft and 6117.5 ft and shale at 6118.0 ft, each called sandstone, each within a few feet of a bed boundary. There the tool reads a few feet of rock at once and records a mixture of two rocks that neither rock's curves describe. The misses are the tool's, not the model's.
Other Kinds of Naive Bayes
The likelihood need not be Gaussian. Multinomial naive Bayes models counts, as of words in a report or grains in a thin section; Bernoulli naive Bayes models presence and absence. The rule is the same: a prior times one likelihood per feature, as if the features were independent within the class.
What These Scores Are
Every score in this section is on the samples the model was fitted to, on one well, and that flatters it. Section 6.2 scores naive Bayes on the field's nine wells, one well held out at a time.