# Proof of a modified Bayes' theorem

I know this question is not very hard to answer, but it posed as a problem for me, so it may pose as a problem to other people too.

We know that Bayes' Theorem is stated using the following formula:
$$Pr(A\big | B) = \frac{Pr(B \big | A)Pr(A)}{Pr(B)}$$ Where $A$ and $B$ are events and $Pr(B) \neq 0$. Now, in Introduction to Statistical Learning by James et al. it is given that

Bayes' Theorem states that $$Pr(Y=k | X=x) = \frac{\pi_kf_k(x)}{\sum_{l=1}^K\pi_lf_l(x)}$$

Where $\pi_k$ is the fraction of the training observations that belong to the $k$ th class, and $f_k(x)$ is the density function which is equivalent to $Pr(X=x|Y=k)$.
How are the two formulas related?

As given, $\pi_k$ is simply the probability that $Y=k$. And it is already given that $f_k(x)=Pr(X=x|Y=k)$. So, the numerators of both the formulas correspond to each other correctly. Now here comes the denominator: (let $K$ denote the total number of classes that $Y$ can take) $$\sum_{l=1}^K\pi_lf_l(x) = \sum_{l=1}^KPr(Y=l)\times Pr(X=x|Y=l) \\ = \sum_{l=1}^KPr(X=x)\times Pr(Y=l|X=x) \\ = Pr(X=x)\times\sum_{l=1}^KPr(Y=l|X=x) \\ = Pr(X=x)\times 1 \\ = Pr(X=x)$$

A shorter and maybe more intuitive way to answer this:

Let's say K=2, with classes $$K_1$$ and $$K_2$$. Remember that according to the Bayes theorem $$Pr(A, B) = Pr(B \big | A)Pr(A)$$.

We can then write the sum as:

$$\sum_{l=1}^K\pi_lf_l(x)=\pi_1f_1(x)+\pi_2f_2(x)$$

Using Bayes: $$= Pr(k=1, X=x) + Pr(k=2, X=x)$$

$$= Pr(X=x)$$