foundations of computational agents
A point estimate for target feature $Y$ on example $e$ is a prediction of the value of $Y(e)$. Let $\widehat{Y}(e)$ be the predicted value for target feature $Y$ on example $e$. The error for this example on this feature is a measure of how close $\widehat{Y}(e)$ is to $Y(e)$.
For regression, when the target feature $Y$ is real valued, both $\widehat{Y}(e)$ and $Y(e)$ are real numbers that can be compared arithmetically.
For classification, when the target feature $Y$ is a discrete function, there are a number of alternatives:
When the domain of $Y$ is binary, one value can be associated with 0, the other value with 1, and a prediction can be some real number. For Boolean features, with domain $\{false,true\}$, we associate 0 with $false$ and 1 with $true$. The predicted value could be any real number or could be restricted to be 0 or 1. Here we assume that the prediction can be any real number, except where explicitly noted. The predicted and actual values can be compared numerically. There is nothing special about $\{0,1\}$ for binary features; it is possible to use $\{-1,1\}$ or to use zero and non-zero.
In a cardinal feature the values are mapped to real numbers. This is appropriate when values in the domain of $Y$ are totally ordered, and the differences between the values are meaningful. In this case, the predicted and actual values can be compared on this scale.
Often, mapping values to the real line is not appropriate even when the values are totally ordered; for example, suppose the values are $short$, $medium$, and $long$. The prediction that the value is “either $short$ or $long$” is very different from the prediction that the value is $medium$. When the domain of a feature is totally ordered, but the differences between the values are not comparable, the feature is called an ordinal feature.
For a totally ordered feature, either cardinal or ordinal, and for a given value $v$, a Boolean feature can be constructed as a cut: a new feature that has value 1 when $Y\le v$ and 0 otherwise. Which cut-values are used to construct features may be chosen according to the data or be selected a priori. Note that a cut for the maximal value in the domain, if there is one, is redundant as it is always true. It is also possible to construct a cut using less-than rather than less-than-or-equal to. Combining cuts allows for features that are true for intervals.
When $Y$ is discrete with domain $\{{v}_{1},\mathrm{\dots},{v}_{k}\}$, where $k>2$, a separate prediction can be made for each ${v}_{i}$. This can be modeled by having a binary indicator variable, ${Y}_{i}$, associated with each value ${v}_{i}$, where ${Y}_{i}(e)=1$ if $Y(e)={v}_{i}$, and ${Y}_{i}(e)=0$ otherwise. For each example, $e$, exactly one of ${Y}_{1}(e)\mathrm{\dots}{Y}_{k}(e)$ will be 1 and the others will be 0. A prediction gives $k$ real numbers – one real number for each ${Y}_{i}$.
A trading agent wants to learn a person’s preference for the length of holidays. The holiday can be for 1, 2, 3, 4, 5, or 6 days.
One representation is to have a real-valued variable ${Y}$ that is the number of days in the holiday.
Another representation is in terms of indicator variables, ${{Y}}_{{\mathrm{1}}}{\mathrm{,}}{\mathrm{\dots}}{\mathrm{,}}{{Y}}_{{\mathrm{6}}}$, where ${{Y}}_{{i}}$ represents the proposition that the person would like to stay for ${i}$ days. For each example, ${{Y}}_{{i}}{\mathrm{=}}{\mathrm{1}}$ when there are ${i}$ days in the holiday, and ${{Y}}_{{i}}{\mathrm{=}}{\mathrm{0}}$ otherwise.
The following are five data points using these two representations:
Example | ${Y}$ |
---|---|
${{e}}_{{1}}$ | 1 |
${{e}}_{{2}}$ | 6 |
${{e}}_{{3}}$ | 6 |
${{e}}_{{4}}$ | 2 |
${{e}}_{{5}}$ | 1 |
Example | ${{Y}}_{{1}}$ | ${{Y}}_{{2}}$ | ${{Y}}_{{3}}$ | ${{Y}}_{{4}}$ | ${{Y}}_{{5}}$ | ${{Y}}_{{6}}$ |
---|---|---|---|---|---|---|
${{e}}_{{1}}$ | 1 | 0 | 0 | 0 | 0 | 0 |
${{e}}_{{2}}$ | 0 | 0 | 0 | 0 | 0 | 1 |
${{e}}_{{3}}$ | 0 | 0 | 0 | 0 | 0 | 1 |
${{e}}_{{4}}$ | 0 | 1 | 0 | 0 | 0 | 0 |
${{e}}_{{5}}$ | 1 | 0 | 0 | 0 | 0 | 0 |
A third representation is to have a binary cut feature of ${Y}{\mathrm{\le}}{i}$ for various values of ${i}$:
Example | ${Y}{\le}{1}$ | ${Y}{\le}{2}$ | ${Y}{\le}{3}$ | ${Y}{\le}{4}$ | ${Y}{\le}{5}$ |
---|---|---|---|---|---|
${{e}}_{{1}}$ | 1 | 1 | 1 | 1 | 1 |
${{e}}_{{2}}$ | 0 | 0 | 0 | 0 | 0 |
${{e}}_{{3}}$ | 0 | 0 | 0 | 0 | 0 |
${{e}}_{{4}}$ | 0 | 1 | 1 | 1 | 1 |
${{e}}_{{5}}$ | 1 | 1 | 1 | 1 | 1 |
A prediction for a new example ${e}$ in the first representation can be any real number, such as $\widehat{{Y}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{3.2}}$.
In the second representation, the learner would predict a value for each ${{Y}}_{{i}}$ for each example. One such prediction may be, for each example ${e}$, predict $\widehat{{{Y}}_{{\mathrm{1}}}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{0.5}}$, $\widehat{{{Y}}_{{\mathrm{2}}}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{0.3}}$, $\widehat{{{Y}}_{{\mathrm{3}}}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{0.1}}$, $\widehat{{{Y}}_{{\mathrm{4}}}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{0.1}}$, $\widehat{{{Y}}_{{\mathrm{5}}}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{0.1}}$, and $\widehat{{{Y}}_{{\mathrm{6}}}}{\mathit{}}{\mathrm{(}}{e}{\mathrm{)}}{\mathrm{=}}{\mathrm{0.5}}$. This is a prediction that the person may like 1 day or 6 days, but will like a stay of 3, 4, or 5 days much less.
In the third representation, the learner could predict a value for ${Y}{\mathrm{\le}}{i}$ for each value of ${i}$. One such prediction may be to predict ${Y}{\mathrm{\le}}{\mathrm{1}}$ with value 0.4, ${Y}{\mathrm{\le}}{i}$ with 0.6, for the other values for ${i}$. It is not rational to predict, for example, that ${Y}{\mathrm{\le}}{\mathrm{2}}$ but not ${Y}{\mathrm{\le}}{\mathrm{4}}$, because one implies the other.
In the following measures of prediction error, $E$ is a set of examples and $\mathbf{T}$ is a set of target features. For target feature $Y\in \mathbf{T}$ and example $e\in E$, the actual value is $Y(e)$ and the predicted value is $\widehat{Y}(e)$.
The 0/1 error on $E$ is the sum of the number of predictions that are wrong:
$$\sum _{e\in E}\sum _{Y\in \mathbf{T}}Y(e)\ne \widehat{Y}(e),$$ |
where $Y(e)\ne \widehat{Y}(e)$ is 0 when false, and 1 when true. This is the number of incorrect predictions. It does not take into account how wrong the predictions are, just whether they are correct or not.
The absolute error on $E$ is the sum of the absolute differences between the actual and predicted values on each example:
$$\sum _{e\in E}\sum _{Y\in \mathbf{T}}\left|Y(e)-\widehat{Y}(e)\right|.$$ |
This is always non-negative, and is only zero when all the predictions exactly fit the observed values. Unlike for the 0/1 error, close predictions are better than far-away predictions.
The sum-of-squares error on $E$ is
$$\sum _{e\in E}\sum _{Y\in \mathbf{T}}{(Y(e)-\widehat{Y}(e))}^{2}.$$ |
This measure treats large errors as much worse than small errors. For example, an error of 2 on an example is as bad as 4 errors of 1, and an error of 10 on one example is as bad as 100 errors of 1. Minimizing sum-of-squares error is equivalent to minimizing the root-mean-square (RMS) error, obtained by dividing by the number of examples and taking the square root. Taking the square root and dividing by a constant do not affect which predictions are minimal.
The worst-case error on $E$ is the maximum absolute difference:
$$\underset{e\in E}{\mathrm{max}}\underset{Y\in \mathbf{T}}{\mathrm{max}}\left|Y(e)-\widehat{Y}(e)\right|.$$ |
In this case, the learner is evaluated by how bad it can be.
These are often described in terms of the norms of the difference between the predicted and actual values. The 0/1 error is the ${\mathbf{L}}_{\mathrm{\U0001d7ce}}$ error, the absolute error is the ${\mathbf{L}}_{\mathrm{\U0001d7cf}}$ error, the sum-of-squares error is the square of the ${\mathbf{L}}_{\mathrm{\U0001d7d0}}$ error, and the worst-case error is the ${\mathbf{L}}_{\mathrm{\infty}}$ error. The sum-of-squares error is often written as ${L}_{2}^{2}$, as the ${L}_{2}$ norm takes the square root of the sum of squares. Taking square roots does not affect which value is the minimum. Note that the ${L}_{0}$ error does not fit the mathematical definition of a norm.
Consider the data of Figure 7.2. Figure 7.3 shows a plot of the training data (filled circles) and three lines, ${{L}}_{{\mathrm{1}}}$, ${{L}}_{{\mathrm{2}}}$, and ${{L}}_{{\mathrm{\infty}}}$, that predict the ${Y}$-value for all ${X}$ points. ${{L}}_{{\mathrm{1}}}$ is the line that minimizes the absolute error, ${{L}}_{{\mathrm{2}}}$ is the line that minimizes the sum-of-squares error, and ${{L}}_{{\mathrm{\infty}}}$ minimizes the worst-case error of the training examples.
As no three points are collinear, any line through any pair of the points minimizes the 0/1, ${{L}}_{{\mathrm{0}}}$, error.
Lines ${{L}}_{{\mathrm{1}}}$ and ${{L}}_{{\mathrm{2}}}$ give similar predictions for ${X}{\mathrm{=}}{\mathrm{1.1}}$; namely, ${{L}}_{{\mathrm{1}}}$ predicts 1.805 and ${{L}}_{{\mathrm{2}}}$ predicts 1.709, whereas the data contain a data point ${\mathrm{(}}{\mathrm{1.1}}{\mathrm{,}}{\mathrm{2.4}}{\mathrm{)}}$. ${{L}}_{{\mathrm{\infty}}}$ predicts 0.7. They give predictions within 1.5 of each other when interpolating in the range ${\mathrm{[}}{\mathrm{1}}{\mathrm{,}}{\mathrm{3}}{\mathrm{]}}$. Their predictions diverge when extrapolating from the data. ${{L}}_{{\mathrm{1}}}$ and ${{L}}_{{\mathrm{\infty}}}$ give very different predictions for ${X}{\mathrm{=}}{\mathrm{5}}$.
An outlier is an example that does not follow the pattern of the other examples. The difference between the lines that minimize the various error measures is most pronounced in how they handle outliers. The point ${\mathrm{(}}{\mathrm{3.9}}{\mathrm{,}}{\mathrm{7}}{\mathrm{)}}$ can be seen as an outlier as the other points are approximately in a line.
The prediction with the least worse-case error for this example, ${{L}}_{{\mathrm{\infty}}}$, only depends on three data points, ${\mathrm{(}}{\mathrm{1.1}}{\mathrm{,}}{\mathrm{2.4}}{\mathrm{)}}$, ${\mathrm{(}}{\mathrm{3.1}}{\mathrm{,}}{\mathrm{2.3}}{\mathrm{)}}$, and ${\mathrm{(}}{\mathrm{3.9}}{\mathrm{,}}{\mathrm{7}}{\mathrm{)}}$, each of which has the same worst-case error for prediction ${{L}}_{{\mathrm{\infty}}}$. The other data points could be at different locations, as long as they are not farther away from ${{L}}_{{\mathrm{\infty}}}$ than these three points.
The prediction that minimizes the absolute error, ${{L}}_{{\mathrm{1}}}$, does not change as a function of the actual ${Y}$-value of the training examples, as long as the points above the line stay above the line, and those below the line stay below. For example, the prediction that minimizes the absolute error would be the same, even if the last data point was ${\mathrm{(}}{\mathrm{3.9}}{\mathrm{,}}{\mathrm{107}}{\mathrm{)}}$ instead of ${\mathrm{(}}{\mathrm{3.9}}{\mathrm{,}}{\mathrm{7}}{\mathrm{)}}$.
Prediction ${{L}}_{{\mathrm{2}}}$ is sensitive to all of the data points; if the ${Y}$-value for any point changes, the line that minimizes the sum-of-squares error will change. Changes to outliers will have more effect on the line than changes to points close to the line.
For the special case where the domain of $Y$ is $\{0,1\}$, and the prediction is in the range $[0,1]$ (and so for Boolean domains where $true$ is treated as 1, and $false$ as 0), the following can also be used to evaluate predictions:
The likelihood of the data is the probability of the data when the predicted value is interpreted as a probability, and each of the examples are predicted independently:
$$\prod _{e\in E}\prod _{Y\in \mathbf{T}}\widehat{Y}{(e)}^{Y(e)}{(1-\widehat{Y}(e))}^{(1-Y(e))}.$$ |
One of $Y(e)$ and $(1-Y(e))$ is 1, and the other is 0. Thus, this product uses $\widehat{Y}(e)$ when $Y(e)=1$ and $(1-\widehat{Y}(e))$ when $Y(e)=0$. A better prediction is one with a higher likelihood. The model with the greatest likelihood is the maximum likelihood model.
The log-likelihood is the logarithm of the likelihood, which is:
$$\sum _{e\in E}\sum _{Y\in \mathbf{T}}\left(Y(e)\mathrm{log}\widehat{Y}(e)+(1-Y(e))\mathrm{log}(1-\widehat{Y}(e))\right).$$ |
A better prediction is one with a higher log-likelihood. To make this into an error term to minimize, the log loss is the negative of the log-likelihood divided by the number of examples.
The log loss is closely related to the notion of entropy. The log loss can be seen as the average number of bits it will take to encode the data given a code that is based on $\widehat{Y}(e)$ treated as a probability.
Information Theory
A bit is a binary digit. Because a bit has two possible values (0 and 1), it can be used to distinguish two items. Two bits can distinguish four items, each associated with either $\colorbox[rgb]{1,1,0.701960784313725}{$00$}$, $\colorbox[rgb]{1,1,0.701960784313725}{$01$}$, $\colorbox[rgb]{1,1,0.701960784313725}{$10$}$, or $\colorbox[rgb]{1,1,0.701960784313725}{$11$}$. In general, $\colorbox[rgb]{1,1,0.701960784313725}{$n$}$ bits can distinguish ${\colorbox[rgb]{1,1,0.701960784313725}{$2$}}^{\colorbox[rgb]{1,1,0.701960784313725}{$n$}}$ items. Thus, we can distinguish $\colorbox[rgb]{1,1,0.701960784313725}{$n$}$ items with ${\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$n$}$ bits. It may be surprising, but we can do better than this using probabilities.
Consider this code to distinguish the elements of the set $\colorbox[rgb]{1,1,0.701960784313725}{$\{$}\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$,$}\colorbox[rgb]{1,1,0.701960784313725}{$b$}\colorbox[rgb]{1,1,0.701960784313725}{$,$}\colorbox[rgb]{1,1,0.701960784313725}{$c$}\colorbox[rgb]{1,1,0.701960784313725}{$,$}\colorbox[rgb]{1,1,0.701960784313725}{$d$}\colorbox[rgb]{1,1,0.701960784313725}{$\}$}$, with $\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$1$}}{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}$, $\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$b$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$1$}}{\colorbox[rgb]{1,1,0.701960784313725}{$4$}}$, $\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$c$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$1$}}{\colorbox[rgb]{1,1,0.701960784313725}{$8$}}$, and $\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$d$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$1$}}{\colorbox[rgb]{1,1,0.701960784313725}{$8$}}$:
$$\begin{array}{cccc}\hfill \colorbox[rgb]{1,1,0.701960784313725}{$a$}& \colorbox[rgb]{1,1,0.701960784313725}{$0$}\hfill & \hfill \colorbox[rgb]{1,1,0.701960784313725}{$c$}& \colorbox[rgb]{1,1,0.701960784313725}{$110$}\hfill \\ \hfill \colorbox[rgb]{1,1,0.701960784313725}{$b$}& \colorbox[rgb]{1,1,0.701960784313725}{$10$}\hfill & \hfill \colorbox[rgb]{1,1,0.701960784313725}{$d$}& \colorbox[rgb]{1,1,0.701960784313725}{$111$}\hfill \end{array}$$ |
This code sometimes uses 1 bit, sometimes 2 bits and sometimes uses 3 bits. On average, it uses
$$\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}\colorbox[rgb]{1,1,0.701960784313725}{$1$}\colorbox[rgb]{1,1,0.701960784313725}{$+$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$b$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}\colorbox[rgb]{1,1,0.701960784313725}{$2$}\colorbox[rgb]{1,1,0.701960784313725}{$+$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$c$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}\colorbox[rgb]{1,1,0.701960784313725}{$3$}\colorbox[rgb]{1,1,0.701960784313725}{$+$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$d$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}\colorbox[rgb]{1,1,0.701960784313725}{$3$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$1$}}{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$+$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}{\colorbox[rgb]{1,1,0.701960784313725}{$4$}}\colorbox[rgb]{1,1,0.701960784313725}{$+$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$3$}}{\colorbox[rgb]{1,1,0.701960784313725}{$8$}}\colorbox[rgb]{1,1,0.701960784313725}{$+$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$3$}}{\colorbox[rgb]{1,1,0.701960784313725}{$8$}}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\colorbox[rgb]{1,1,0.701960784313725}{$1$}\colorbox[rgb]{1,1,0.701960784313725}{$\u2064$}\frac{\colorbox[rgb]{1,1,0.701960784313725}{$3$}}{\colorbox[rgb]{1,1,0.701960784313725}{$4$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$\text{bits.}$}$$ |
For example, the string $\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$c$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$b$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$b$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$d$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$a$}$ with 8 characters has code $\colorbox[rgb]{1,1,0.701960784313725}{$00110010101110$}$, which uses 14 bits.
With this code, $\colorbox[rgb]{1,1,0.701960784313725}{$-$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$a$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\colorbox[rgb]{1,1,0.701960784313725}{$1$}$ bit is required to distinguish $\colorbox[rgb]{1,1,0.701960784313725}{$a$}$ from the other symbols. Distinguishing $\colorbox[rgb]{1,1,0.701960784313725}{$b$}$ uses $\colorbox[rgb]{1,1,0.701960784313725}{$-$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$b$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\colorbox[rgb]{1,1,0.701960784313725}{$2$}$ bits. Distinguishing $\colorbox[rgb]{1,1,0.701960784313725}{$c$}$ or $\colorbox[rgb]{1,1,0.701960784313725}{$d$}$ requires $\colorbox[rgb]{1,1,0.701960784313725}{$-$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$c$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$=$}\colorbox[rgb]{1,1,0.701960784313725}{$3$}$ bits.
It is possible to build a code that, to identify $\colorbox[rgb]{1,1,0.701960784313725}{$x$}$, requires $\colorbox[rgb]{1,1,0.701960784313725}{$-$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}$ bits (or the integer greater than this). Suppose there is a sequence of symbols we want to transmit or store and we know the probability distribution over the symbols. A symbol $\colorbox[rgb]{1,1,0.701960784313725}{$x$}$ with probability $\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}$ can use $\colorbox[rgb]{1,1,0.701960784313725}{$-$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}$ bits. To transmit a sequence, each symbol requires, on average,
$$\colorbox[rgb]{1,1,0.701960784313725}{$\sum $}_{\colorbox[rgb]{1,1,0.701960784313725}{$x$}}\colorbox[rgb]{1,1,0.701960784313725}{$-$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}$$ |
bits to send it. This is called the information content or entropy of the distribution. This value just depends on the probability distribution of the symbols.
Analogous to conditioning in probability, the expected number of bits it takes to describe a distribution for $\colorbox[rgb]{1,1,0.701960784313725}{$x$}$ given evidence $\colorbox[rgb]{1,1,0.701960784313725}{$e$}$ is
$$\colorbox[rgb]{1,1,0.701960784313725}{$\sum $}_{\colorbox[rgb]{1,1,0.701960784313725}{$x$}}\colorbox[rgb]{1,1,0.701960784313725}{$-$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$\mid $}\colorbox[rgb]{1,1,0.701960784313725}{$e$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$\mid $}\colorbox[rgb]{1,1,0.701960784313725}{$e$}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$.$}$$ |
For a test that can distinguish the cases where $\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}$ is true from the cases where $\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}$ is false, the expected information after the test is
$$\colorbox[rgb]{1,1,0.701960784313725}{$-$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}\colorbox[rgb]{1,1,0.701960784313725}{$\sum $}_{\colorbox[rgb]{1,1,0.701960784313725}{$x$}}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$\mid $}\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$\mid $}\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$-$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{\neg}$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}\colorbox[rgb]{1,1,0.701960784313725}{$\sum $}_{\colorbox[rgb]{1,1,0.701960784313725}{$x$}}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$\mid $}\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{\neg}$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$*$}{\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{log}$}}_{\colorbox[rgb]{1,1,0.701960784313725}{$2$}}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$P$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$($}\colorbox[rgb]{1,1,0.701960784313725}{$x$}\colorbox[rgb]{1,1,0.701960784313725}{$\mid $}\colorbox[rgb]{1,1,0.701960784313725}{$\mathrm{\neg}$}\colorbox[rgb]{1,1,0.701960784313725}{$$}\colorbox[rgb]{1,1,0.701960784313725}{$\alpha $}\colorbox[rgb]{1,1,0.701960784313725}{$)$}\colorbox[rgb]{1,1,0.701960784313725}{$.$}$$ |
The entropy of the distribution minus the expected information after the test is called the information gain of the test.
Consider the length of holiday data of Example 7.3. Suppose there are no input features, so all of the examples get the same prediction.
In the first representation, the prediction that minimizes the sum of absolute errors on the training data presented in Example 7.3 is 2, with an error of 10. The prediction that minimizes the sum-of-squares error on the training data is 3.2. The prediction the minimizes the worst-case error is 3.5.
For the second representation, the prediction that minimizes the sum of absolute errors for the training examples is to predict 0 for each ${{Y}}_{{i}}$. The prediction that minimizes the sum-of-squares error for the training examples is ${{Y}}_{{\mathrm{1}}}{\mathrm{=}}{\mathrm{0.4}}$, ${{Y}}_{{\mathrm{2}}}{\mathrm{=}}{\mathrm{0.1}}$, ${{Y}}_{{\mathrm{3}}}{\mathrm{=}}{\mathrm{0}}$, ${{Y}}_{{\mathrm{4}}}{\mathrm{=}}{\mathrm{0}}$, ${{Y}}_{{\mathrm{5}}}{\mathrm{=}}{\mathrm{0}}$, and ${{Y}}_{{\mathrm{6}}}{\mathrm{=}}{\mathrm{0.4}}$. This is also the prediction that maximizes the likelihood of the training data. The prediction that minimizes the worst-case error for the training examples is to predict 0.5 for ${{Y}}_{{\mathrm{1}}}$, ${{Y}}_{{\mathrm{2}}}$, and ${{Y}}_{{\mathrm{6}}}$ and to predict ${\mathrm{0}}$ for the other features.
Thus, which prediction is preferred depends on how the prediction is represented and how it will be evaluated.