foundations of computational agents
Instead of just choosing the most likely hypothesis, it is typically more useful to use the posterior probability distribution of hypotheses, in what is called Bayesian learning.
Suppose $E$ is the set of training examples and a test example has inputs $X=x$ (written as $x$) and target $Y$. The aim is to compute $P(Y\mid x\wedge E)$. This is the probability distribution of the target variable given the particular inputs and the examples. The role of a model is to be the assumed generator of the examples. If $M$ is a set of disjoint and covering models:
$P(Y\mid x\wedge E)$ | $={\displaystyle \sum _{m\in M}}P(Y\wedge m\mid x\wedge E)$ | |||
$={\displaystyle \sum _{m\in M}}P(Y\mid m\wedge x\wedge E)\ast P(m\mid x\wedge E)$ | ||||
$={\displaystyle \sum _{m\in M}}P(Y\mid m\wedge x)\ast P(m\mid E).$ | (10.3) |
The first two equalities follow from the definition of (conditional) probability. The last equality relies on two assumptions: the model includes all the information about the examples that is necessary for a particular prediction, $P(Y\mid m\wedge x\wedge E)=P(Y\mid m\wedge x)$, and the model does not change depending on the inputs of the new example, $P(m\mid x\wedge E)=P(m\mid E)$. Instead of choosing the best model, Bayesian learning relies on model averaging, averaging over the predictions of all the models, where each model is weighted by its posterior probability given the training examples, as in Equation 10.3.
$P(m\mid E)$ can be computed using Bayes’ rule (Equation 10.1), in terms of the prior $P(E)$, the likelihood $P(E\mid m)$, and a normalization term.
A common assumption is that examples $E=\{{e}_{1},\mathrm{\dots},{e}_{k}\}$ are independent and identically distributed (i.i.d.) given model $m$, which means examples ${e}_{i}$ and ${e}_{j}$, for $i\ne j$, are independent given $m$:
$$P(E\mid m)=\prod _{i=1}^{k}P({e}_{i}\mid m).$$ |
The i.i.d. assumption can be represented as the belief network of Figure 10.1.
A standard reasoning technique in such a network is to condition on the observed ${e}_{i}$ and to either query an unobserved ${e}_{j}$ variable, which provides a probabilistic prediction for unseen examples, or query $m$, which provides a distribution over models.
The inference methods of the previous chapter could be used to compute the posterior probabilities. However, the exact methods presented are only applicable when $m$ is finite, because they involve enumerating the domains of the variables. However, $m$ is usually more complicated (often including real-valued components) than these exact techniques can handle, and approximation methods are required. For some cases, the inference can be exact using special-case algorithms.
The simplest case (Section 10.2.1) is to learn probabilities of a single discrete variable. Bayesian learning can also be used for learning decision trees (Section 10.2.3), learning the structure and probabilities of belief networks (Section 10.4), and more complicated cases.
The simplest learning task is to learn a single Boolean random variable, $Y$, with no input features, as in Section 7.2.2. The aim is to learn the posterior distribution of $Y$ conditioned on the training examples.
Consider the problem of predicting the next toss of a thumbtack (drawing pin), where the outcomes $Tails$ and $Heads$ are as follows:
Suppose you tossed a thumbtack a number of times and observed $E$, a particular sequence of ${n}_{0}$ instances of $Tails$ and ${n}_{1}$ instances of $Heads$. Assume the tosses are independent, and that $Heads$ occurs with probability $\varphi $. The likelihood is
$$P(E\mid \varphi )={\varphi}^{{n}_{1}}\ast {(1-\varphi )}^{{n}_{0}}.$$ |
This is a maximum when the log-likelihood
$$\mathrm{log}P(E\mid \varphi )={n}_{1}\ast \mathrm{log}\varphi +{n}_{0}\ast \mathrm{log}(1-\varphi )$$ |
is a maximum, and the negation of the average log-likelihood, the categorical log loss, is a minimum, which occur when $\varphi =\frac{{n}_{1}}{{n}_{0}+{n}_{1}}$.
Note that if ${n}_{1}=0$, then $\varphi $ is zero, which would indicate that $Heads$ is impossible; similarly, ${n}_{1}=0$ would predict that $Tails$ is impossible, which is an instance of overfitting. A MAP model would also take into account a prior.
Reverend Thomas Bayes [1763] had the insight to treat a probability as a real-valued random variable. For a Boolean variable, $Y$, a real-valued variable, $\varphi $, on the interval $[0,1]$ represents the probability of $Y$. Thus, by definition of $\varphi $, $P(Y=true\mid \varphi )=\varphi $ and $P(Y=false\mid \varphi )=1-\varphi $.
Suppose, initially, an agent considers all values in the interval $[0,1]$ equally likely to be the value of $\varphi $. This can be modeled with the variable $\varphi $ having a uniform distribution over the interval $[0,1]$. This is the probability density function labeled ${n}_{0}=\mathrm{\hspace{0.17em}0},{n}_{1}=\mathrm{\hspace{0.17em}0}$ in Figure 10.2.
The probability distribution of $\varphi $ is updated by conditioning on observed examples. Let the examples $E$ be the particular sequence of observations that resulted in ${n}_{1}$ occurrences of $Y=true$ and ${n}_{0}$ occurrences of $Y=false$. Bayes’ rule and the i.i.d. assumption gives
$P(\varphi \mid E)$ | $={\displaystyle \frac{P(E\mid \varphi )\ast P(\varphi )}{P(E)}}$ | ||
$\propto {\varphi}^{{n}_{1}}\ast {(1-\varphi )}^{{n}_{0}}\ast P(\varphi ).$ |
The denominator is a normalizing constant to ensure the area under the curve is 1.
Consider the thumbtack of Example 10.1 with a uniform prior.
With a uniform prior and no observations, shown as the ${n}_{0}=1,{n}_{1}=2$ line of Figure 10.2, the MAP estimate is undefined – every point is a maximum – and the expected value is 0.5.
When a single heads and no tails is observed, the distribution is a straight line from point $(0,0)$ to point $(1,2)$. The most likely prediction – the MAP estimate – is $\varphi =1$. The expected value of the resulting distribution is $\varphi =2/3$.
When two heads and one tails are observed, the resulting distribution is the ${n}_{0}=1,{n}_{1}=2$ line of Figure 10.2. The mode is at $2/3$ and the expected value is $3/5$.
Figure 10.2 gives some posterior distributions of the variable $\varphi $ based on different sample sizes, given a uniform prior. The cases are $({n}_{0}=\mathrm{\hspace{0.17em}1},{n}_{1}=\mathrm{\hspace{0.17em}2})$, $({n}_{0}=\mathrm{\hspace{0.17em}2},{n}_{1}=\mathrm{\hspace{0.17em}4})$, and $({n}_{0}=\mathrm{\hspace{0.17em}4},{n}_{1}=\mathrm{\hspace{0.17em}8})$. Each of these peak at the same place, namely at $\frac{2}{3}$. More training examples make the curve sharper.
When eight heads and four tails are observed, the mode is at $2/3$ and the expected value is $5/14$. Notice how the expected value for this case is closer to the empirical proportion of heads in the training data than when ${n}_{0}=1,{n}_{1}=2$, even though the modes are the same empirical proportion.
The distribution of this example is known as the beta distribution; it is parameterized by two counts, ${\alpha}_{0}$ and ${\alpha}_{1}$, and a probability $\varphi $. Traditionally, the ${\alpha}_{i}$ parameters for the beta distribution are one more than the counts; thus, ${\alpha}_{i}={n}_{i}+1$. The beta distribution is
$$Bet{a}^{{\alpha}_{0},{\alpha}_{1}}(\varphi )=\frac{{\varphi}^{{\alpha}_{1}-1}\ast {(1-\varphi )}^{{\alpha}_{0}-1}}{Z}$$ |
where $Z$ is a normalizing constant that ensures the integral over all values is 1. Thus, the uniform distribution on $[0,1]$ is the beta distribution $Bet{a}^{1,1}$.
The mode – the value with the maximum probability – of the beta distribution $Bet{a}^{{\alpha}_{0},{\alpha}_{1}}$ is $\varphi =\frac{{\alpha}_{0}-1}{{\alpha}_{0}+{\alpha}_{0}-2}$.
The expected value of the beta distribution $Bet{a}^{{\alpha}_{0},{\alpha}_{1}}$ is $\varphi =\frac{{\alpha}_{0}}{{\alpha}_{0}+{\alpha}_{0}}$
Thus, the expectation of the beta distribution with a uniform prior gives Laplace smoothing. This shows that Laplace smoothing is optimal for the thought experiment where a probability was selected uniformly in [0,1], training and test data were generated using that probability, and evaluated on test data.
The prior does not need to be the uniform distribution. A common prior is to use a beta distribution for the prior of $\varphi $, such as
$$P(\varphi )={\varphi}^{{c}_{1}-1}\ast {(1-\varphi )}^{{c}_{0}-1}$$ |
corresponding to ${c}_{1}$ pseudo-examples with outcome true, and ${c}_{0}$ false pseudo-examples. In this case, the posterior probability given examples $E$ that consists of a particular sequence of ${n}_{0}$ false and ${n}_{1}$ true examples is
$$P(\varphi \mid E)\propto {\varphi}^{{c}_{1}+{n}_{1}-1}\ast {(1-\varphi )}^{{c}_{0}+{n}_{0}-1}.$$ |
In this case, the MAP estimate for $\varphi $, the probability of true, is
$$p=\frac{{c}_{1}+{n}_{1}-1}{{c}_{0}+{n}_{0}+{c}_{1}+{n}_{1}-2}$$ |
and the expected value is
$$p=\frac{{c}_{1}+{n}_{1}}{{c}_{0}+{n}_{0}+{c}_{1}+{n}_{1}}.$$ |
This prior has the same form as the posterior; both are described in terms of a ration of counts. A prior that has the same form as a posterior is called a conjugate prior.
Note that $E$ is the particular sequence of observations made. If the observation was just that there were a total of ${n}_{0}$ occurrences of $Y=false$ and ${n}_{1}$ occurrences of $Y=true$, you would get a different answer, because you would have to take into account all the possible sequences that could have given this count. This is known as the binomial distribution.
In addition to using the posterior distribution of $\varphi $ to derive the expected value, it can be used to answer other questions such as: What is the probability that the posterior probability, $\varphi $, is in the range $[a,b]$? In other words, derive $P((\varphi \ge a\wedge \varphi \le b)\mid E)$. This is the problem that Bayes [1763] solved in his posthumously published paper. The solution published – although in much more cumbersome notation because calculus had not been invented when it was written – was
$$\frac{{\int}_{a}^{b}{p}^{n}\ast {(1-p)}^{m-n}}{{\int}_{0}^{1}{p}^{n}\ast {(1-p)}^{m-n}}.$$ |
This kind of knowledge is used in poll surveys when it may be reported that a survey is correct with an error of at most $5\%$, $19$ times out of $20$, and in a probably approximately correct (PAC) estimate. It guarantees an error at most $\u03f5$ at least $1-\delta $ of the time as follows:
If an agent predicts $\frac{a+b}{2}$, the midpoint of the range $[a,b]$, it will have error less than or equal to $\u03f5=\frac{b-a}{2}$, exactly when the hypothesis is in $[a,b]$.
Let $\delta =1-P(\varphi \ge a\wedge \varphi \le b\mid E)$. Then $1-\delta $ is $P(\varphi \ge a\wedge \varphi \le b\mid E)$, so
choosing the midpoint will result in an error at most $\u03f5$ in $1-\delta $ of the time.
Hoeffding’s inequality gives worst-case results, whereas the Bayesian estimate gives the expected number. The worst case provides looser bounds than the expected case.
Suppose $Y$ is a categorical variable with $k$ possible values. A distribution over a categorical variable is called a multinomial distribution. The Dirichlet distribution is the generalization of the beta distribution to cover categorical variables. The Dirichlet distribution with two sorts of parameters, the “counts” ${\alpha}_{1},\mathrm{\dots},{\alpha}_{k}$, and the probability parameters ${p}_{1},\mathrm{\dots},{p}_{k}$, is
$$Dirichle{t}^{{\alpha}_{1},\mathrm{\dots},{\alpha}_{k}}({p}_{1},\mathrm{\dots},{p}_{k})=\frac{{\prod}_{j=1}^{k}{p}_{j}^{{\alpha}_{j}-1}}{Z}$$ |
where ${p}_{i}$ is the probability of the $i$th outcome (and so $0\le {p}_{i}\le 1$) and ${\alpha}_{i}$ is a positive real number and $Z$ is a normalizing constant that ensures the integral over all the probability values is 1. You can think of ${a}_{i}$ as one more than the count of the $i$th outcome, ${\alpha}_{i}={n}_{i}+1$. The Dirichlet distribution looks like Figure 10.2 along each dimension (i.e., as each ${p}_{j}$ varies between 0 and 1).
For the Dirichlet distribution, the expected value outcome $i$ (averaging over all ${p}_{j}$) is
$$\frac{{\alpha}_{i}}{{\sum}_{j}{\alpha}_{j}}.$$ |
The reason that the ${\alpha}_{i}$ parameters are one more than the counts in the definitions of the beta and Dirichlet distributions is to make this formula simple.
Suppose an agent must predict a value for $Y$ with domain $\{{y}_{1},\mathrm{\dots},{y}_{k}\}$, and there are no inputs. The agent starts with a positive pseudocount ${c}_{i}$ for each ${y}_{i}$. These counts are chosen before the agent has seen any of the data. Suppose the agent observes training examples with ${n}_{i}$ data points having $Y={y}_{i}$. The probability of $Y$ is estimated using the expected value
$$P(Y={y}_{i})=\frac{{c}_{i}+{n}_{i}}{{\sum}_{{i}^{\prime}}{c}_{{i}^{\prime}}+{n}_{{i}^{\prime}}}.$$ |
When the dataset is empty (all ${n}_{i}=0$), the ${c}_{i}$ are used to estimate probabilities. An agent does not have to start with a uniform prior; it could start with any prior distribution. If the agent starts with a prior that is a Dirichlet distribution, its posterior will be a Dirichlet distribution.
Thus, the beta and Dirichlet distributions provide a justification for using pseudocounts for estimating probabilities. A pseudocount of 1 corresponds to Laplace smoothing.
The use of pseudocounts also gives us a way to combine expert knowledge and data. Often a single agent does not have good data but may have access to multiple experts who have varying levels of expertise and who give different probabilities.
There are a number of problems with obtaining probabilities from experts:
experts’ reluctance to give an exact probability value that cannot be refined
representing the uncertainty of a probability estimate
combining the estimates from multiple experts
combining expert opinion with actual data.
Rather than expecting experts to give probabilities, the experts can provide counts. Instead of giving a real number for the probability of $A$, an expert gives a pair of numbers as $$ that is interpreted as though the expert had observed $n$ occurrences of $A$ out of $m$ trials. Essentially, the experts provide not only a probability, but also an estimate of the size of the dataset on which their estimate is based.
The counts from different experts can be combined together by adding the components to give the pseudocounts for the system. You should not necessarily believe an expert’s sample size, as people are often overconfident in their abilities. Instead, the size can be estimated taking into account the experiences of the experts. Whereas the ratio between the counts reflects the probability, different levels of confidence are reflected in the absolute values. Consider different ways to represent the probability $2/3$. The pair $$, with two positive examples out of three examples, reflects extremely low confidence that would quickly be dominated by data or other experts’ estimates. The pair $$ reflects more confidence – a few examples would not change it much, but tens of examples would. Even hundreds of examples would have little effect on the prior counts of the pair $$. However, with millions of data points, even these prior counts would have little impact on the resulting probability estimate.
A Bayes classifier is a probabilistic model that is used for supervised learning. A Bayes classifier is based on the idea that the role of a class is to predict the values of features for members of that class. Examples are grouped in classes because they have common values for some of the features. The learning agent learns how the features depend on the class and uses that model to predict the classification of a new example.
The simplest case is the naive Bayes classifier, which makes the independence assumption that the input features are conditionally independent of each other given the classification. The independence of the naive Bayes classifier is embodied in a belief network where the features are the nodes, the target feature (the classification) has no parents, and the target feature is the only parent of each input feature. This belief network requires the probability distributions $P(Y)$ for the target feature, or class, $Y$ and $P({X}_{i}\mid Y)$ for each input feature ${X}_{i}$. For each example, the prediction is computed by conditioning on observed values for the input features and querying the classification. Multiple target variables can be modeled and learned separately.
Suppose an agent wants to predict the user action given the data of Figure 7.1. For this example, the user action is the classification. The naive Bayes classifier for this example corresponds to the belief network of Figure 10.3. The input features form variables that are children of the classification.
The model of Figure 10.3 corresponds to $m$ in Figure 10.1.
Given an example with inputs ${X}_{1}={v}_{1},\mathrm{\dots},{X}_{k}={v}_{k}$, Bayes’ rule is used to compute the posterior probability distribution of the example’s classification, $Y$:
$P(Y\mid {X}_{1}$ | $={v}_{1},\mathrm{\dots},{X}_{k}={v}_{k})$ | ||
$=$ | $\frac{P({X}_{1}={v}_{1},\mathrm{\dots},{X}_{k}={v}_{k}\mid Y)\ast P(Y)}{P({X}_{1}={v}_{1},\mathrm{\dots},{X}_{k}={v}_{k})}$ | ||
$=$ | $\frac{P(Y)\ast {\prod}_{i=1}^{k}P({X}_{i}={v}_{i}\mid Y)}{{\sum}_{Y}P(Y)\ast {\prod}_{i=1}^{k}P({X}_{i}={v}_{i}\mid Y)}$ |
where the denominator is a normalizing constant to ensure the probabilities sum to 1.
Unlike many other models of supervised learning, the naive Bayes classifier can handle missing data where not all features are observed; the agent conditions on the features that are observed, which assumes the data is missing at random. Naive Bayes is optimal – it makes no independence assumptions beyond missing at random – if only a single ${X}_{i}$ is observed. As more of the ${X}_{i}$ are observed, the accuracy depends on how independent the ${X}_{i}$ are given $Y$.
If $Y$ is Boolean and every ${X}_{i}$ is observed, naive Bayes is isomorphic to a logistic regression model; see page 9.3.3 for a derivation. They have identical predictions when the logistic regression weight for ${X}_{i}$ is the logarithm of the likelihood ratio, $\mathrm{log}P({X}_{i}\mid h)/P({X}_{i}\mid \neg h)$. They are typically learned differently – but don’t need to be – with logistic regression trained to minimize log loss and naive Bayes trained for the conditional probabilities to be the MAP model or the expected value, given a prior.
To learn a classifier, the distributions of $P(Y)$ and $P({X}_{i}\mid Y)$ for each input feature can be learned from the data. Each conditional probability distribution $P({X}_{i}\mid Y)$ may be treated as a separate learning problem for each value of $Y$, for example using beta or Dirichlet distributions.
Suppose an agent wants to predict the user action given the data of Figure 7.1. For this example, the user action is the classification. The naive Bayes classifier for this example corresponds to the belief network of Figure 10.3. The training examples are used to determine the probabilities required for the belief network.
Suppose the agent uses the empirical frequencies as the probabilities for this example. (Thus, it is not using any pseudocounts.) The maximum likelihood probabilities that can be derived from these data are
$P(User\mathrm{\_}action=reads)=9\u221518=0.5$ |
$P(Author=known\mid User\mathrm{\_}action=reads)=2\u22153$ |
$P(Author=known\mid User\mathrm{\_}action=skips)=2\u22153$ |
$P(Thread=new\mid User\mathrm{\_}action=reads)=7\u22159$ |
$P(Thread=new\mid User\mathrm{\_}action=skips)=1\u22153$ |
$P(Length=long\mid User\mathrm{\_}action=reads)=0$ |
$P(Length=long\mid User\mathrm{\_}action=skips)=7\u22159$ |
$P(Where\mathrm{\_}read=home\mid User\mathrm{\_}action=reads)=4\u22159$ |
$P(Where\mathrm{\_}read=home\mid User\mathrm{\_}action=skips)=4\u22159.$ |
Based on these probabilities, the features $Author$ and $Where\mathrm{\_}read$ have no predictive power because knowing either does not change the probability that the user will read the article.
If the maximum likelihood probabilities are used, some conditional probabilities may be zero. This means that some features become predictive: knowing just one feature value can rule out a category. It is possible that some combinations of observations are impossible, and the classifier will have a divide-by-zero error if these are observed. See Exercise 10.1. This is a problem not necessarily with using a Bayes classifier, but rather with using empirical frequencies as probabilities.
The alternative to using the empirical frequencies is to incorporate pseudocounts. Pseudocounts can be engineered to have desirable behavior, before any data is observed and as more data is acquired.
Consider how to learn the probabilities for the help system of Example 9.36, where a helping agent infers what help page a user is interested in based on the words in the user’s query to the help system. Let’s treat the query as a set of words.
The learner must learn $P(H)$. It could start with a pseudocount for each ${h}_{i}$. Pages that are a priori more likely should have a higher pseudocount.
Similarly, the learner needs the probability $P({w}_{j}\mid {h}_{i})$, the probability that word ${w}_{j}$ will be used given the help page is ${h}_{i}$. Because you may want the system to work even before it has received any data, the prior for these probabilities should be carefully designed, taking into account the frequency of words in the language, the words in the help page itself, and other information obtained by experience with other (help) systems.
Assume the following positive counts, which are observed counts plus suitable pseudocounts:
${c}_{i}$ the number of times ${h}_{i}$ was the correct help page
$s={\sum}_{i}{c}_{i}$ the total count
${u}_{ij}$ the number of times ${h}_{i}$ was the correct help page and word ${w}_{j}$ was used in the query.
From these counts an agent can estimate the required probabilities
$P({h}_{i})$ | $={c}_{i}/s$ | ||
$P({w}_{j}\mid {h}_{i})$ | $={u}_{ij}/{c}_{i}$ |
from which $P(H\mid q)$, the posterior distribution of help pages conditioned on the set of words $q$ in a user’s query, can be computed; see Example 10.3. It is necessary to use the words not in the query as well as the words in the query. For example, if a help page is about printing, the work “print” may be very likely to be used. The fact that “print” is not in a query is strong evidence that this is not the appropriate help page.
The system could present the help page(s) with the highest probability given the query.
When a user claims to have found the appropriate help page, the counts for that page and the words in the query are updated. Thus, if the user indicates that ${h}_{i}$ is the correct page, the counts $s$ and ${c}_{i}$ are incremented, and for each word ${w}_{j}$ used in the query, ${u}_{ij}$ is incremented. This model does not use information about the wrong page. If the user claims that a page is not the correct page, this information is not used.
The biggest challenge in building such a help system is not in the learning but in acquiring useful data. In particular, users may not know whether they have found the page they were looking for. Thus, users may not know when to stop and provide the feedback from which the system learns. Some users may never be satisfied with a page. Indeed, there may not exist a page they are satisfied with, but that information never gets fed back to the learner. Alternatively, some users may indicate they have found the page they were looking for, even though there may be another page that was more appropriate. In the latter case, the correct page may end up with its counts so low, it is never discovered. See Exercise 10.2.
Although there are some cases where the naive Bayes classifier does not produce good results, it is extremely simple, easy to implement, and often works very well. It is a good method to try for a new problem.
In general, the naive Bayes classifier works well when the independence assumption is appropriate, that is, when the class is a good predictor of the other features and the other features are independent given the class. This may be appropriate for natural kinds, where the classes have evolved because they are useful in distinguishing the objects that humans want to distinguish. Natural kinds are often associated with nouns, such as the class of dogs or the class of chairs.
The naive Bayes classifier can be expanded in a number of ways:
Some input features could be parents of the classification and some be children. The probability of the classification given its parents could be represented as a decision tree or a squashed linear function or a neural network.
The children of the classification do not have to be modeled as independent. In a tree-augmented naive Bayes (TAN) network, the children of the class variable are allowed to have zero or one other parents as long as the resulting graph is acyclic. This allows for a simple model that accounts for interdependencies among the children, while retaining efficient inference, as the tree structured in the children has a small treewidth.
Structure can be incorporated into the class variable. A latent tree model decomposes the class variable into a number of latent variables that are connected together in a tree structure. Each observed variable is a child of one of the latent variables. The latent variables allow a model of the dependence between the observed variables.
The previous examples did not need the prior on the structure of models, as all the models were equally complex. However, learning decision trees requires a bias, typically in favor of smaller decision trees. The prior probability provides this bias.
If there are no examples with the same values for the input features but different values for the target feature, there are always multiple decision trees that fit the data perfectly. For every assignment of values that did not appear in the training set, there are decision trees that perfectly fit the training set, and make opposite predictions on the unseen examples. See the no-free-lunch theorem. If there is a possibility of noise, none of the trees that perfectly fit the training set may be the best model.
Consider the data of Figure 7.1, where the learner is required to predict the user’s actions.
One possible decision tree is the one given on the left of Figure 7.8. Call this decision tree ${d}_{2}$; the subscript being the depth. The likelihood of the data is $P(E\mid {d}_{2})=1$. That is, ${d}_{2}$ accurately fits the data.
Another possible decision tree is the one with no internal nodes, and a single leaf that predicts $reads$ with probability $\frac{1}{2}$. This is the most likely tree with no internal nodes, given the data. Call this decision tree ${d}_{0}$. The likelihood of the data given this model is
$$P(E\mid {d}_{0})={\left(\frac{1}{2}\right)}^{9}\ast {\left(\frac{1}{2}\right)}^{9}\approx 1.5\ast {10}^{-6}.$$ |
Another possible decision tree is one on the right of Figure 7.8, with one split on $Length$ and with probabilities on the leaves given by $P(reads\mid Length=long)=0$ and $P(reads\mid Length=short)=\frac{9}{11}$. Note that $\frac{9}{11}$ is the empirical frequency of $reads$ among the training set with $Length=short$. Call this decision tree ${d}_{1a}$. The likelihood of the data given this model is
$$P(E\mid {d}_{1a})={1}^{7}\ast {\left(\frac{9}{11}\right)}^{9}\ast {\left(\frac{2}{11}\right)}^{2}\approx 0.0543.$$ |
These are just three of the possible decision trees. Which is best depends on the prior on trees. The likelihood of the data is multiplied by the prior probability of the decision trees to determine the posterior probability of the decision tree.
To find a most likely model $m$ given examples $Es$ – a model that maximizes $P(m\mid Es)$ – you can apply Bayes’ rule, ignore the denominator (which doesn’t depend on $m$), and so maximize $P(E\mid m)\ast P(m)$; see Formula 10.2. Taking the negative of the logarithm (base 2), means you can minimize
$$-{\mathrm{log}}_{2}P(E\mid m)-{\mathrm{log}}_{2}P(m).$$ |
This can be interpreted in terms of information theory. The term $-{\mathrm{log}}_{2}P(E\mid m)$ is the number of bits it takes to describe the data given the model $m$. The term $-{\mathrm{log}}_{2}P(m)$ is the number of bits it takes to describe the model. A model that minimizes this sum is a minimum description length (MDL) model. The MDL principle is to choose the model that minimizes the number of bits it takes to describe both the model and the data given the model.
One way to think about the MDL principle is that the aim is to communicate the data as succinctly as possible. To communicate the data, first communicate the model, then communicate the data in terms of the model. The number of bits it takes to communicate the data using a model is the number of bits it takes to communicate the model plus the number of bits it takes to communicate the data in terms of the model.
As the logarithm function is monotonically increasing, the MAP model is the same as the MDL model. Choosing a model with the highest posterior probability is the same as choosing a model with a minimum description length.
The description length provides common units for probabilities and model complexity; they can both be described in terms of bits.
In Example 10.6, the definition of the priors on decision trees was left unspecified. The notion of a description length provides a basis for assigning priors to decision trees.
One code for a tree for a Boolean output with Boolean input features might be as follows. A decision tree is either 0 followed by a fixed-length probability, or 1 followed by a bit string representing a condition (an input feature) followed by the tree when the condition is false followed by the tree for when the condition is true. The condition might take $\lceil {\mathrm{log}}_{2}m\rceil $, where $m$ is the number of input features. The probability could either be a fixed-length bit string, or depend on the data (see below). See Exercise 10.8.
It is often useful to approximate the description length of the model. One way to approximate the description length is to consider just representing the probabilistic parameters of the model. Let $|t|$ be the number of probabilistic parameters of the model $t$. For a decision tree with probabilities at the leaves, $|t|$ is the number of leaves. For a linear function or a neural network, $|t|$ is the number of numerical parameters.
Suppose $|E|$ is the number of training examples. There are at most $|E|+1$ different probabilities the model needs to distinguish, because that probability is derived from the counts, and there can be from 0 to $|E|$ examples with a particular value true in the dataset. It takes ${\mathrm{log}}_{2}(|E|+1)\approx {\mathrm{log}}_{2}(|E|)$ bits to distinguish these probabilities. Thus, the problem of finding the MDL model can be approximated by minimizing
$$-{\mathrm{log}}_{2}P(E\mid t)+|t|\ast {\mathrm{log}}_{2}(|E|).$$ |
This value is the Bayesian information criteria (BIC) score.