# The indicator function

## In words...

The indicator function of an event returns 1 when the event occurs and 0 otherwise.

The expectation of the indicator function is equal to the probability of the event.

The indicator function is typically used to define the loss function used in classification. The property related to its expectation then implies that the classification risk is the probability of misclassification.

## In pictures...

Here is a plot of the indicator function $\I{X \in [a,b]}$:

You can drag and drop the bounds $a$ and $b$ to modify the interval.

And here is a plot of the product of this indicator function
with a Gaussian probability density function $p_X(x)$:

The shaded area corresponds to the integral of this product, which is the expectation of the indicator function and also represents the probability of the random variable $X$ taking a value in the interval $[a,b]$:
$P_X([a,b]) =$

## In maths...

The indicator function of an event $E$ is defined as $$\I{E} = \begin{cases} 1, & \mbox{if } E \mbox{ occurs},\\ 0, & \mbox{otherwise.} \end{cases}$$

With a probability space $(\X,\Sigma,P_X)$, where $\Sigma$ is a $\sigma$-algebra on $\X$ and $P_X$ is the distribution of the random variable $X$ taking values in $\X$, the expectation of the indicator of an event $A\subseteq \X$, $\I{A} = \I{X\in A}$, is the probability of the event: $$\E_X [ \I{X\in A}] = \int_{\X} \I{X\in A}\,p_X(x)\,dx = \int_{A} 1\,p_X(x)\,dx + \int_{\overline{A}} 0\,p_X(x)\,dx = P_X(A) = P(X\in A)$$ with $\overline{A} = \X \setminus A$.