Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Appendix: Bayes Decision Theory — Discrete Features

Introduction

In the general formulation of Bayes Decision Theory, we aim to minimize the probability of error (or more generally, the expected risk) by assigning a feature vector x to the class ωi\omega_i that maximizes the posterior probability P(ωi∣x)P(\omega_i | \mathbf{x}). Using Bayes’ theorem, this is often equivalent to maximizing the product of the likelihood P(x∣ωi)P(\mathbf{x} | \omega_i) and the prior probability P(ωi)P(\omega_i):

Choose ωi such that P(x∣ωi)P(ωi)≥P(x∣ωj)P(ωj) for all j≠i\text{Choose } \omega_i \text{ such that } P(\mathbf{x} | \omega_i) P(\omega_i) \ge P(\mathbf{x} | \omega_j) P(\omega_j) \text{ for all } j \neq i

While the framework remains the same whether the features are continuous or discrete, the nature of the features significantly impacts how we model and estimate the class-conditional probability density (or probability mass function) P(x∣ωi)P(\mathbf{x} | \omega_i). This section focuses on the case where the feature vector x=[x1,x2,...,xd]T\mathbf{x} = [x_1, x_2, ..., x_d]^T consists of discrete features.

Challenges with Discrete Features

When features xjx_j are discrete, x\mathbf{x} can take on a finite number of possible values. Let VjV_j be the number of possible values for feature xjx_j. Then the total number of possible feature vectors x\mathbf{x} is V=∏j=1dVjV = \prod_{j=1}^{d} V_j.

Estimating P(x∣ωi)P(\mathbf{x} | \omega_i) directly involves estimating the probability for each possible configuration of x\mathbf{x} for each class ωi\omega_i.

Modeling P(x∣ωi)P(\mathbf{x} | \omega_i) for Discrete Features: The Naive Bayes Assumption

Due to the challenges above, directly estimating the full joint probability P(x∣ωi)=P(x1,x2,...,xd∣ωi)P(\mathbf{x} | \omega_i) = P(x_1, x_2, ..., x_d | \omega_i) is often infeasible. A common and simplifying approach is to assume conditional independence of the features given the class.

The Naive Bayes Assumption

The Naive Bayes assumption states that the features xjx_j are independent of each other, given the class ωi\omega_i. Mathematically:

P(x∣ωi)=P(x1,x2,...,xd∣ωi)≈∏j=1dP(xj∣ωi)P(\mathbf{x} | \omega_i) = P(x_1, x_2, ..., x_d | \omega_i) \approx \prod_{j=1}^{d} P(x_j | \omega_i)

This assumption dramatically simplifies the problem: instead of estimating one large joint probability table, we only need to estimate dd smaller probability distributions P(xj∣ωi)P(x_j | \omega_i) for each class ωi\omega_i.

Parameter Estimation and Smoothing

The parameters P(xj=v∣ωi)P(x_j=v | \omega_i) and the prior probabilities P(ωi)P(\omega_i) are typically estimated from the training data using Maximum Likelihood Estimation (MLE) or smoothed versions (like Laplace smoothing) to avoid zero probabilities:

Case Study: Independent Binary Features (Section 2.9.1)

A particularly important special case arises when all dd features are binary, i.e., xj∈{0,1}x_j \in \{0, 1\}. This is common in areas like document classification (presence/absence of words) or medical diagnosis (presence/absence of symptoms).

Let’s define the probability that feature jj is present (takes value 1) for class ωi\omega_i as:

pji=P(xj=1∣ωi)(Eq.84 concept)p_{ji} = P(x_j=1 | \omega_i) \quad \quad (Eq. 84 \text{ concept})

Consequently, the probability that the feature is absent (takes value 0) is:

P(xj=0∣ωi)=1−pjiP(x_j=0 | \omega_i) = 1 - p_{ji}

We can write the class-conditional probability for a single feature xjx_j using the Bernoulli formula:

P(xj∣ωi)=pjixj(1−pji)1−xj(Eq.85)P(x_j | \omega_i) = p_{ji}^{x_j} (1 - p_{ji})^{1-x_j} \quad \quad (Eq. 85)

This formula works whether xj=1x_j=1 or xj=0x_j=0.

Under the Naive Bayes assumption (conditional independence), the full class-conditional probability for the feature vector x=[x1,...,xd]T\mathbf{x} = [x_1, ..., x_d]^T is:

P(x∣ωi)=∏j=1dP(xj∣ωi)=∏j=1dpjixj(1−pji)1−xj(Eq.86)P(\mathbf{x} | \omega_i) = \prod_{j=1}^{d} P(x_j | \omega_i) = \prod_{j=1}^{d} p_{ji}^{x_j} (1 - p_{ji})^{1-x_j} \quad \quad (Eq. 86)

Deriving the Discriminant Function

To classify a new sample x\mathbf{x}, we use the decision rule based on the discriminant functions gi(x)g_i(\mathbf{x}). For convenience, we use the log-posterior (ignoring the constant P(x)P(\mathbf{x}) term):

gi(x)=log⁡P(x∣ωi)+log⁡P(ωi)(Eq.87 base)g_i(\mathbf{x}) = \log P(\mathbf{x} | \omega_i) + \log P(\omega_i) \quad \quad (Eq. 87 \text{ base})

Substituting the expression for P(x∣ωi)P(\mathbf{x} | \omega_i):

gi(x)=log⁡(∏j=1dpjixj(1−pji)1−xj)+log⁡P(ωi)g_i(\mathbf{x}) = \log \left( \prod_{j=1}^{d} p_{ji}^{x_j} (1 - p_{ji})^{1-x_j} \right) + \log P(\omega_i)

Using the properties of logarithms (log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b and log⁡(ab)=blog⁡a\log(a^b) = b \log a):

gi(x)=∑j=1dlog⁡(pjixj(1−pji)1−xj)+log⁡P(ωi)g_i(\mathbf{x}) = \sum_{j=1}^{d} \log \left( p_{ji}^{x_j} (1 - p_{ji})^{1-x_j} \right) + \log P(\omega_i)

gi(x)=gi(x)=∑j=1d[log⁡(pjixj)+log⁡((1−pji)1−xj)]+log⁡P(ωi)g_i(\mathbf{x}) =g_i(\mathbf{x}) = \sum_{j=1}^{d} \left[ \log(p_{ji}^{x_j}) + \log((1 - p_{ji})^{1-x_j}) \right] + \log P(\omega_i)
gi(x)=∑j=1d[xjlog⁡pji+(1−xj)log⁡(1−pji)]+log⁡P(ωi)(Eq.88 structure)g_i(\mathbf{x}) = \sum_{j=1}^{d} \left[ x_j \log p_{ji} + (1-x_j) \log (1 - p_{ji}) \right] + \log P(\omega_i) \quad \quad (Eq. 88 \text{ structure})

We can rearrange this expression to highlight its linear form with respect to the features xjx_j. Let’s expand the term inside the summation:

xjlog⁡pji+(1−xj)log⁡(1−pji)=xjlog⁡pji+log⁡(1−pji)−xjlog⁡(1−pji)x_j \log p_{ji} + (1-x_j) \log (1 - p_{ji}) = x_j \log p_{ji} + \log (1 - p_{ji}) - x_j \log (1 - p_{ji})

=xj(log⁡pji−log⁡(1−pji))+log⁡(1−pji)= x_j \left( \log p_{ji} - \log (1 - p_{ji}) \right) + \log (1 - p_{ji})

=xjlog⁡(pji1−pji)+log⁡(1−pji)= x_j \log \left( \frac{p_{ji}}{1 - p_{ji}} \right) + \log (1 - p_{ji})

The term log⁡(pji1−pji)\log \left( \frac{p_{ji}}{1 - p_{ji}} \right) is the log-odds or logit of the probability pjip_{ji}.

Substituting this back into the equation for gi(x)g_i(\mathbf{x}):

gi(x)=∑j=1d[xjlog⁡(pji1−pji)+log⁡(1−pji)]+log⁡P(ωi)g_i(\mathbf{x}) = \sum_{j=1}^{d} \left[ x_j \log \left( \frac{p_{ji}}{1 - p_{ji}} \right) + \log (1 - p_{ji}) \right] + \log P(\omega_i)

Separating the terms that depend on xjx_j from those that do not:

gi(x)=∑j=1d(log⁡pji1−pji)⏟wjixj+[∑k=1dlog⁡(1−pki)+log⁡P(ωi)]⏟wi0(Eq. 89 form)g_i(\mathbf{x}) = \sum_{j=1}^{d} \underbrace{\left( \log \frac{p_{ji}}{1 - p_{ji}} \right)}_{w_{ji}} x_j + \underbrace{\left[ \sum_{k=1}^{d} \log (1 - p_{ki}) + \log P(\omega_i) \right]}_{w_{i0}} \quad \quad (\text{Eq. 89 form})

This shows that the discriminant function gi(x)g_i(\mathbf{x}) is linear in the features xjx_j:

gi(x)=wiTx+wi0g_i(\mathbf{x}) = \mathbf{w}_i^T \mathbf{x} + w_{i0}

where:

Key Result: For binary features under the Naive Bayes assumption, the optimal Bayes discriminant function gi(x)g_i(\mathbf{x}) is a linear discriminant function. This provides an interesting link between generative models (like Naive Bayes, which models P(x∣ωi)P(\mathbf{x} | \omega_i) and P(ωi)P(\omega_i)) and discriminative models (which directly model the decision boundary or discriminant functions, often assuming linearity).

The decision boundary between two classes, say ωi\omega_i and ωk\omega_k, is found by setting gi(x)=gk(x)g_i(\mathbf{x}) = g_k(\mathbf{x}), which leads to a linear equation in x\mathbf{x}:

(wi−wk)Tx+(wi0−wk0)=0(\mathbf{w}_i - \mathbf{w}_k)^T \mathbf{x} + (w_{i0} - w_{k0}) = 0

Estimation

The parameters pji=P(xj=1∣ωi)p_{ji} = P(x_j=1 | \omega_i) and P(ωi)P(\omega_i) are estimated from the training data, often using MLE or MAP (e.g., with Laplace smoothing).

Conclusion

Handling discrete features in Bayesian decision theory often requires simplifying assumptions due to the curse of dimensionality. The Naive Bayes assumption (conditional independence of features given the class) is a common and effective approach.

While the independence assumption might seem overly simplistic (“naive”), Naive Bayes classifiers often perform surprisingly well in practice, particularly in domains like text classification.