St · Statistics & Probability

How to Find a Gaussian Classifier’s Decision Boundary

Published By the 9to5Science editorial team

At a glance

  1. 1. Specify both classes

    Write the mean, covariance, and prior probability for each class; one class-conditional Gaussian alone is not enough.

  2. 2. Compare posterior scores

    Use the log likelihood plus log prior for each class, then set the two scores equal to find the boundary.

  3. 3. Check the covariances

    Shared covariance gives a linear boundary; different covariances generally give a quadratic boundary.

  4. 4. Apply the decision rule

    Classify on the side with the larger posterior score, accounting for any unequal error costs.

A Gaussian model does not determine a binary decision boundary by itself. You need a probability model for each class, along with the class prior probabilities and a rule for deciding which kinds of errors matter.

For the usual Bayes classifier with equal costs for misclassification, the boundary consists of points where the two class posterior probabilities are equal. The calculation also shows why a shared covariance matrix gives a straight boundary, while different covariance matrices usually produce a quadratic one.

Set up the two class models

Let the observed feature vector be x∈Rdx \in \mathbb{R}^d, and let the class label be Y∈{0,1}Y \in \{0,1\}. Assume the class-conditional distributions are

x∣Y=k∼N(μk,Σk),k∈{0,1},x \mid Y=k \sim \mathcal{N}(\mu_k,\Sigma_k), \qquad k\in\{0,1\},

with prior probabilities πk=P(Y=k)\pi_k=P(Y=k). Each covariance matrix is assumed to be positive definite so that the usual Gaussian density is defined.

Bayes’ rule says that the posterior probability of class kk is proportional to its prior times its class-conditional density:

P(Y=k∣x)∝πkp(x∣Y=k).P(Y=k\mid x) \propto \pi_k p(x\mid Y=k).

With equal costs for the two types of classification error, predict class 1 when P(Y=1∣x)>P(Y=0∣x)P(Y=1\mid x)>P(Y=0\mid x). The decision boundary is where these probabilities are equal.

General Gaussian boundary

Taking logarithms is convenient because it turns products into sums. After dropping the Gaussian constant −d2log⁡(2π)-\frac{d}{2}\log(2\pi), the score for class kk is

gk(x)=log⁡πk−12log⁡∣Σk∣−12(x−μk)TΣk−1(x−μk).g_k(x)=\log\pi_k-\frac{1}{2}\log|\Sigma_k|-\frac{1}{2}(x-\mu_k)^T\Sigma_k^{-1}(x-\mu_k).

The boundary is the set of points satisfying

g1(x)=g0(x).g_1(x)=g_0(x).

Predict class 1 where g1(x)>g0(x)g_1(x)>g_0(x), and class 0 where g0(x)>g1(x)g_0(x)>g_1(x). When Σ0\Sigma_0 and Σ1\Sigma_1 differ, the inverse-covariance terms generally leave squared and cross-product terms in xx. The boundary is therefore generally quadratic (though special parameter choices can simplify it).

Shared covariance gives a linear boundary

If both classes have the same covariance matrix, Σ0=Σ1=Σ\Sigma_0=\Sigma_1=\Sigma, their quadratic terms in xx cancel when you subtract the scores. The boundary becomes

(μ1−μ0)TΣ−1x−12(μ1TΣ−1μ1−μ0TΣ−1μ0)+log⁡π1π0=0.(\mu_1-\mu_0)^T\Sigma^{-1}x -\frac{1}{2}\left(\mu_1^T\Sigma^{-1}\mu_1-\mu_0^T\Sigma^{-1}\mu_0\right) +\log\frac{\pi_1}{\pi_0}=0.

This is a linear equation in the features. The normal vector to the boundary is Σ−1(μ1−μ0)\Sigma^{-1}(\mu_1-\mu_0); the priors shift its position. If the priors are equal, the log-prior term vanishes. This shared-covariance model is often called linear discriminant analysis (LDA). The unequal-covariance Gaussian classifier is often called quadratic discriminant analysis (QDA).

Worked one-dimensional example

Suppose

X∣Y=0∼N(−1,4),X∣Y=1∼N(2,4),X\mid Y=0\sim\mathcal{N}(-1,4),\qquad X\mid Y=1\sim\mathcal{N}(2,4),

and the class priors are π0=0.6\pi_0=0.6 and π1=0.4\pi_1=0.4. The variance is shared, so there is a single threshold. Setting the two class scores equal gives

x=μ0+μ12+σ2μ1−μ0log⁡π0π1=12+43log⁡(1.5)≈1.041.x=\frac{\mu_0+\mu_1}{2}+\frac{\sigma^2}{\mu_1-\mu_0}\log\frac{\pi_0}{\pi_1} =\frac{1}{2}+\frac{4}{3}\log(1.5)\approx 1.041.

The score for class 1 increases with xx, so predict class 1 when x>1.041x>1.041 and class 0 when x<1.041x<1.041. The more common class 0 pushes the threshold to the right of the midpoint, making the classifier require stronger evidence for class 1. At the threshold, the posterior probabilities are equal.

If the error costs differ

Equal posterior probabilities are the boundary only when the two kinds of error have equal cost. Let C10C_{10} be the cost of predicting 1 when the true class is 0, and C01C_{01} the cost of predicting 0 when the true class is 1. Predict class 1 when

P(Y=1∣x)P(Y=0∣x)>C10C01.\frac{P(Y=1\mid x)}{P(Y=0\mid x)}>\frac{C_{10}}{C_{01}}.

The boundary is then where the posterior odds equal this cost ratio, rather than 1. The equal-cost rule is recovered when C10=C01C_{10}=C_{01}.

Common mistakes

  • Using only one class distribution: A boundary compares classes. Knowing p(x∣Y=1)p(x\mid Y=1) without p(x∣Y=0)p(x\mid Y=0) does not determine where to classify.
  • Ignoring priors: The means and covariances alone are not enough when the classes are not equally likely. Priors can move the boundary.
  • Assuming every Gaussian boundary is linear: Linearity requires shared covariance (or another special simplification). Different covariance matrices usually yield a quadratic boundary.
  • Confusing a density with a posterior: A point can have a larger likelihood under one class but still have a larger posterior under another if the prior probabilities differ.

If a problem gives just one Gaussian mean and covariance matrix, check whether it also specifies the competing class model, priors, and decision costs. Without those, there is no unique binary decision boundary.

References

  1. Pattern Recognition and Machine Learning, Christopher M. Bishop
  2. The Elements of Statistical Learning, Trevor Hastie, Robert Tibshirani, and Jerome Friedman

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.