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 & 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 poweredTulis LaTeX menggunakan AI

Editor LaTeX AI Terbaik, Alternatif Overleaf

Octree membantu peneliti dari 15+ universitas menulis makalah penelitian lebih cepat menggunakan AI

  • Hasilkan diagram TikZ yang indah menggunakan AI
  • Unggah gambar dan konversi ke LaTeX dengan mulus
  • Dapatkan bantuan instan untuk menulis dan memformat makalah penelitian