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 머신러닝 및 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 poweredAI로 LaTeX 작성

최고의 AI LaTeX 편집기, Overleaf 대안

Octree는 15개 이상의 대학의 연구자들이 AI를 사용하여 논문을 더 빠르게 작성하도록 도움

  • AI로 아름다운 TikZ 다이어그램 생성
  • 이미지를 업로드하고 LaTeX로 원활하게 변환
  • 논문 작성 및 서식에 대한 즉각적인 지원 받기