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 التعلم الآلي والذكاء الاصطناعي →

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 poweredاكتب LaTeX باستخدام الذكاء الاصطناعي

أفضل محرر LaTeX بالذكاء الاصطناعي، بديل Overleaf

يساعد Octree الباحثين من أكثر من 15 جامعة على كتابة أوراق البحث بشكل أسرع باستخدام الذكاء الاصطناعي

  • أنشئ رسوم TikZ جميلة باستخدام الذكاء الاصطناعي
  • ارفع صورة وحولها إلى LaTeX بسلاسة
  • احصل على مساعدة فورية في كتابة وتنسيق أوراق البحث