Conditional Probability in LaTeX (p(y | x))

p(y∣x)p(y | x)
LaTeX command
p(y | x)
Package
No package needed: built into LaTeX
Mode
Text and math mode

Where it is used

Conditional probability of y given x, such as a classifier's predicted label distribution for an input.

Discriminative models learn p(y | x) directly, while generative models learn p(x | y) and p(y) and apply Bayes' rule, p(y|x) = p(x|y)p(y)/p(x). The bare vertical bar typed as | is an ordinary character and gets no space around it; \mid is a relation and yields p(y \mid x), which reads better and is what most style guides recommend. For a tall conditioning expression, \middle| between \left( and \right) scales the bar with the parentheses. Subscripts like p_\theta(y \mid x) indicate the model's parameters.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

p(y∣x)=p(x∣y) p(y)p(x)p(y \mid x) = \frac{p(x \mid y)\, p(y)}{p(x)}
\documentclass{article}
\begin{document}
Conditional Probability: $p(y | x)$

\[ p(y \mid x) = \frac{p(x \mid y)\, p(y)}{p(x)} \]
\end{document}

Related symbols

All Machine Learning at AI →

Frequently asked questions

How do I write Conditional Probability in LaTeX?
Type p(y | x) in math mode, for example $p(y \mid x) = \frac{p(x \mid y)\, p(y)}{p(x)}$. It works in plain LaTeX without loading any package.
Which package do I need for p(y | x)?
None. p(y | x) is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use p(y | x) in text mode, or only in math mode?
Both. p(y | x) compiles in running text as well as inside $...$; in a formula keep it in math mode so it gets math fonts and spacing.
Math poweredSumulat ng LaTeX gamit ang AI

Pinakamahusay na AI LaTeX Editor, Alternatibo sa Overleaf

Tinutulungan ng Octree ang mga researcher mula sa 15+ na unibersidad na sumulat ng research papers nang mas mabilis gamit ang AI

  • Gumawa ng magagandang TikZ diagrams gamit ang AI
  • Mag-upload ng larawan at i-convert ito sa LaTeX nang walang problema
  • Makakuha ng instant na tulong sa pagsulat at pag-format ng research papers