0

I am trying to compute the Gaussian Naive Bayes formula in latex, and what I obtained until now is:

$P(x_{\mathrm{i}|$y$}) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}}$

but I got some issues..

The final formula should look like this:

enter image description here

Can you help me please?

Thank you very much in advanced!!

2 Answers2

3

Just alternative code using \mid (to have symmetrical blank spaces instead of |) and \exp commands.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{equation} P(x_{i}\mid y) = \frac{1}{\sqrt{2\pi \sigma_y^{2}}} \exp \left(-\frac{(x_{i} -\mu_{y})^2}{2\sigma_y^{2}} \right) \end{equation} \end{document}

enter image description here

Sebastiano
  • 54,118
1

Does this solve your question?

\documentclass[]{article}
\usepackage{amsmath}
\begin{document}

\begin{equation} P(x_i|y) = \frac{1}{\sqrt{2\pi \sigma_y^2}} exp \left( - \frac{(x_i - \mu_y)^2}{2\sigma_y^2} \right) \end{equation} \end{document}

You dont need the equation environment or the \amsmath package. You could also simply replace your code with:

$P(x_i|y) = \frac{1}{\sqrt{2\pi \sigma_y^2}} exp \left( - \frac{(x_i - \mu_y)^2}{2\sigma_y^2} \right)$