Problem statement
The problem of pattern recognition can be stated as follows: Given an unknown function
g
:
X
→
Y
{\displaystyle g:{\mathcal {X}}\rightarrow {\mathcal {Y}}}
(the ground truth) that maps input instances
x
∈
X
{\displaystyle {\boldsymbol {x}}\in {\mathcal {X}}}
to output labels
y
∈
Y
{\displaystyle y\in {\mathcal {Y}}}
, along with training data
D
=
{
(
x
1
,
y
1
)
,
…
,
(
x
n
,
y
n
)
}
{\displaystyle \mathbf {D} =\{({\boldsymbol {x}}_{1},y_{1}),\dots ,({\boldsymbol {x}}_{n},y_{n})\}}
assumed to represent accurate examples of the mapping, produce a function
h
:
X
→
Y
{\displaystyle h:{\mathcal {X}}\rightarrow {\mathcal {Y}}}
that approximates as closely as possible the correct mapping
g
{\displaystyle g}
. (For example, if the problem is filtering spam, then
x
i
{\displaystyle {\boldsymbol {x}}_{i}}
is some representation of an email and
y
{\displaystyle y}
is either "spam" or "non-spam"). In order for this to be a well-defined problem, "approximates as closely as possible" needs to be defined rigorously. In decision theory, this is defined by specifying a loss function or cost function that assigns a specific value to "loss" resulting from producing an incorrect label. The goal then is to minimize the expected loss, with the expectation taken over the probability distribution of
X
{\displaystyle {\mathcal {X}}}
. In practice, neither the distribution of
X
{\displaystyle {\mathcal {X}}}
nor the ground truth function
g
:
X
→
Y
{\displaystyle g:{\mathcal {X}}\rightarrow {\mathcal {Y}}}
are known exactly, but can be computed only empirically by collecting a large number of samples of
X
{\displaystyle {\mathcal {X}}}
and hand-labeling them using the correct value of
Y
{\displaystyle {\mathcal {Y}}}
(a time-consuming process, which is typically the limiting factor in the amount of data of this sort that can be collected). The particular loss function depends on the type of label being predicted. For example, in the case of classification, the simple zero-one loss function is often sufficient. This corresponds simply to assigning a loss of 1 to any incorrect labeling and implies that the optimal classifier minimizes the error rate on independent test data (i.e. counting up the fraction of instances that the learned function
h
:
X
→
Y
{\displaystyle h:{\mathcal {X}}\rightarrow {\mathcal {Y}}}
labels wrongly, which is equivalent to maximizing the number of correctly classified instances). The goal of the learning procedure is then to minimize the error rate (maximize the correctness) on a "typical" test set.
For a probabilistic pattern recognizer, the problem is instead to estimate the probability of each possible output label given a particular input instance, i.e., to estimate a function of the form
p
(
l
a
b
e
l
|
x
,
θ
)
=
f
(
x
;
θ
)
{\displaystyle p({\rm {label}}|{\boldsymbol {x}},{\boldsymbol {\theta }})=f\left({\boldsymbol {x}};{\boldsymbol {\theta }}\right)}
where the feature vector input is
x
{\displaystyle {\boldsymbol {x}}}
, and the function f is typically parameterized by some parameters
θ
{\displaystyle {\boldsymbol {\theta }}}
. In a discriminative approach to the problem, f is estimated directly. In a generative approach, however, the inverse probability
p
(
x
|
l
a
b
e
l
)
{\displaystyle p({{\boldsymbol {x}}|{\rm {label}}})}
is instead estimated and combined with the prior probability
p
(
l
a
b
e
l
|
θ
)
{\displaystyle p({\rm {label}}|{\boldsymbol {\theta }})}
using Bayes' rule, as follows:
p
(
l
a
b
e
l
|
x
,
θ
)
=
p
(
x
|
l
a
b
e
l
,
θ
)
p
(
l
a
b
e
l
|
θ
)
∑
L
∈
all labels
p
(
x
|
L
)
p
(
L
|
θ
)
.
{\displaystyle p({\rm {label}}|{\boldsymbol {x}},{\boldsymbol {\theta }})={\frac {p({{\boldsymbol {x}}|{\rm {label,{\boldsymbol {\theta }}}}})p({\rm {label|{\boldsymbol {\theta }}}})}{\sum _{L\in {\text{all labels}}}p({\boldsymbol {x}}|L)p(L|{\boldsymbol {\theta }})}}.}
When the labels are continuously distributed (e.g., in regression analysis), the denominator involves integration rather than summation:
p
(
l
a
b
e
l
|
x
,
θ
)
=
p
(
x
|
l
a
b
e
l
,
θ
)
p
(
l
a
b
e
l
|
θ
)
∫
L
∈
all labels
p
(
x
|
L
)
p
(
L
|
θ
)
d
L
.
{\displaystyle p({\rm {label}}|{\boldsymbol {x}},{\boldsymbol {\theta }})={\frac {p({{\boldsymbol {x}}|{\rm {label,{\boldsymbol {\theta }}}}})p({\rm {label|{\boldsymbol {\theta }}}})}{\int _{L\in {\text{all labels}}}p({\boldsymbol {x}}|L)p(L|{\boldsymbol {\theta }})\operatorname {d} L}}.}
The value of
θ
{\displaystyle {\boldsymbol {\theta }}}
is typically learned using maximum a posteriori (MAP) estimation. This finds the best value that simultaneously meets two conflicting objects: To perform as well as possible on the training data (smallest error-rate) and to find the simplest possible model. Essentially, this combines maximum likelihood estimation with a regularization procedure that favors simpler models over more complex models. In a Bayesian context, the regularization procedure can be viewed as placing a prior probability
p
(
θ
)
{\displaystyle p({\boldsymbol {\theta }})}
on different values of
θ
{\displaystyle {\boldsymbol {\theta }}}
. Mathematically:
θ
∗
=
arg
max
θ
p
(
θ
|
D
)
{\displaystyle {\boldsymbol {\theta }}^{*}=\arg \max _{\boldsymbol {\theta }}p({\boldsymbol {\theta }}|\mathbf {D} )}
where
θ
∗
{\displaystyle {\boldsymbol {\theta }}^{*}}
is a point estimate (such as the MAP estimate) used for
θ
{\displaystyle {\boldsymbol {\theta }}}
in point-estimate evaluation, and
p
(
θ
|
D
)
{\displaystyle p({\boldsymbol {\theta }}|\mathbf {D} )}
, the posterior probability of
θ
{\displaystyle {\boldsymbol {\theta }}}
, is given by Bayes' theorem:
p
(
θ
|
D
)
=
[
∏
i
=
1
n
p
(
y
i
|
x
i
,
θ
)
]
p
(
θ
)
p
(
D
)
∝
[
∏
i
=
1
n
p
(
y
i
|
x
i
,
θ
)
]
p
(
θ
)
,
{\displaystyle p({\boldsymbol {\theta }}|\mathbf {D} )={\frac {\left[\prod _{i=1}^{n}p(y_{i}|{\boldsymbol {x}}_{i},{\boldsymbol {\theta }})\right]p({\boldsymbol {\theta }})}{p(\mathbf {D} )}}\propto \left[\prod _{i=1}^{n}p(y_{i}|{\boldsymbol {x}}_{i},{\boldsymbol {\theta }})\right]p({\boldsymbol {\theta }}),}
where
D
=
{
(
x
i
,
y
i
)
}
i
=
1
n
{\displaystyle \mathbf {D} =\{({\boldsymbol {x}}_{i},y_{i})\}_{i=1}^{n}}
represents the training dataset, and
p
(
D
)
=
∫
[
∏
i
=
1
n
p
(
y
i
|
x
i
,
θ
)
]
p
(
θ
)
d
θ
{\displaystyle p(\mathbf {D} )=\int \left[\prod _{i=1}^{n}p(y_{i}|{\boldsymbol {x}}_{i},{\boldsymbol {\theta }})\right]p({\boldsymbol {\theta }})\,d{\boldsymbol {\theta }}}
is the marginal likelihood (or Bayesian evidence).
In the full Bayesian approach, instead of selecting a single parameter vector
θ
∗
{\displaystyle {\boldsymbol {\theta }}^{*}}
, the probability of a label
y
∗
{\displaystyle y^{*}}
for a new query instance
x
∗
{\displaystyle {\boldsymbol {x}}^{*}}
given the dataset
D
{\displaystyle \mathbf {D} }
is computed by integrating over all possible values of
θ
{\displaystyle {\boldsymbol {\theta }}}
, weighted according to the posterior probability:
p
(
y
∗
|
x
∗
,
D
)
=
∫
p
(
y
∗
|
x
∗
,
θ
)
p
(
θ
|
D
)
d
θ
=
1
p
(
D
)
∫
p
(
y
∗
|
x
∗
,
θ
)
[
∏
i
=
1
n
p
(
y
i
|
x
i
,
θ
)
]
p
(
θ
)
d
θ
.
{\displaystyle p(y^{*}|{\boldsymbol {x}}^{*},\mathbf {D} )=\int p(y^{*}|{\boldsymbol {x}}^{*},{\boldsymbol {\theta }})p({\boldsymbol {\theta }}|\mathbf {D} )\operatorname {d} {\boldsymbol {\theta }}={\frac {1}{p(\mathbf {D} )}}\int p(y^{*}|{\boldsymbol {x}}^{*},{\boldsymbol {\theta }})\left[\prod _{i=1}^{n}p(y_{i}|{\boldsymbol {x}}_{i},{\boldsymbol {\theta }})\right]p({\boldsymbol {\theta }})\operatorname {d} {\boldsymbol {\theta }}.}