Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update naive-bayes.md #1656

Merged
merged 13 commits into from Mar 1, 2021
24 changes: 21 additions & 3 deletions chapter_appendix-mathematics-for-deep-learning/naive-bayes.md
Expand Up @@ -168,11 +168,29 @@ By itself, this expression does not get us any further. We still must estimate r

$$ \hat{y} = \mathrm{argmax}_y \> \prod_{i=1}^d p(x_i \mid y) p(y).$$

If we can estimate $\prod_i p(x_i=1 \mid y)$ for every $i$ and $y$, and save its value in $P_{xy}[i, y]$, here $P_{xy}$ is a $d\times n$ matrix with $n$ being the number of classes and $y\in\{1, \ldots, n\}$. In addition, we estimate $p(y)$ for every $y$ and save it in $P_y[y]$, with $P_y$ a $n$-length vector. Then for any new example $\mathbf x$, we could compute

$$ \hat{y} = \mathrm{argmax}_y \> \prod_{i=1}^d P_{xy}[x_i, y]P_y[y],$$
If we can estimate $\prod_i p(x_i=1 \mid y)$ for every $i$ and $y$, and save its value in $P_{xy}[i, y]$, here $P_{xy}$ is a $d\times n$ matrix with $n$ being the number of classes and $y\in\{1, \ldots, n\}$, i.e.,


$$
P_{xy}[i, y] =
\begin{cases}
P_{xy}[i, y] & \text{for } t_i=1 ;\\
1 - P_{xy}[i, y] & \text{for } t_i = 0 .
\end{cases}
$$

In addition, we estimate $p(y)$ for every $y$ and save it in $P_y[y]$, with $P_y$ a $n$-length vector. Then for any new example $\mathbf x$, we could compute

$$
\begin{aligned}
\hat{y}
&= \mathrm{argmax}_y \ \prod_{i=1}^d P_y[y] \times P_{xy}[i, y]\\
&= \mathrm{argmax}_y \ \prod_{i=1}^d P_y[y]\ P_{xy}[i, y]^{t_i}\, \left(1 - P_{xy}[i, y]\right)^{1-t_i},
\end{aligned}
$$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @particle1331 , apology for a bit delay. Here is the reason why this "eqlabel" is not render well:

"$$\begin{aligned} ... \end{aligned}$$" needs to be on one single line.

Please check (search \begin{aligned}) in this example: https://github.com/d2l-ai/d2l-en/blob/master/chapter_linear-networks/linear-regression.md.

Let me know if you are still having trouble solving it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Sorry for the delay as well. Thank you for pointing me towards this solution.
It worked. :=)

http://preview.d2l.ai/d2l-en/PR-1656/chapter_appendix-mathematics-for-deep-learning/naive-bayes.html

:eqlabel:`eq_naive_bayes_estimation`


for any $y$. So our assumption of conditional independence has taken the complexity of our model from an exponential dependence on the number of features $\mathcal{O}(2^dn)$ to a linear dependence, which is $\mathcal{O}(dn)$.


Expand Down