Introduction to Regularization and Model Selection
You can read the notes from the previous lecture from Andrew Ng's CS229 course on Deep Learning here.
Suppose we are trying select among several different models for a learning problem. For instance, we might be using a polynomial regression model , and wish to decide if should be , or . How can we automatically select a model that represents a good tradeoff between the twin evils of bias and variance[1]? Alternatively, suppose we want to automatically choose the bandwidth parameter for locally weighted regression, or the parameter for our -regularized SVM. How can we do that?
For the sake of concreteness, in these notes we assume we have some finite set of models that we're trying to select among. For instance, in our first example above, the model would be an -th order polynomial regression model. (The generalization to infinite is not hard.[2]) Alternatively, if we are trying to decide between using an SVM, a neural network or logistic regression, then may contain these models.
1. Cross validation
Lets suppose we are, as usual, given a training set . Given what we know about empirical risk minimization, here's what might initially seem like a algorithm, resulting from using empirical risk minimization for model selection:
- Train each model
on , to get some hypothesis . - Pick the hypotheses with the smallest training error.
This algorithm does not work. Consider choosing the order of a polynomial. The higher the order of the polynomial, the better it will fit the training set , and thus the lower the training error. Hence, this method will always select a high-variance, high-degree polynomial model, which we saw previously is often poor choice.
Here's an algorithm that works better. In hold-out cross validation (also called simple cross validation), we do the following:
- Randomly split
into (say, of the data) and (the remaining ). Here, is called the hold-out cross validation set. - Train each model
on only, to get some hypothesis . - Select and output the hypothesis
that had the smallest error on the hold out cross validation set. (Recall, denotes the empirical error of on the set of examples in .)
By testing on a set of examples that the models were not trained on, we obtain a better estimate of each hypothesis 's true generalization error, and can then pick the one with the smallest estimated generalization error. Usually, somewhere between of the data is used in the hold out cross validation set, and is a typical choice.
Optionally, step 3 in the algorithm may also be replaced with selecting the model according to , and then retraining on the entire training set . (This is often a good idea, with one exception being learning algorithms that are be very sensitive to perturbations of the initial conditions and/or data. For these methods, doing well on does not necessarily mean it will also do well on , and it might be better to forgo this retraining step.)
The disadvantage of using hold out cross validation is that it "wastes" about of the data. Even if we were to take the optional step of retraining the model on the entire training set, it's still as if we're trying to find a good model for a learning problem in which we had training examples, rather than training examples, since we're testing models that were trained on only examples each time. While this is fine if data is abundant and/or cheap, in learning problems in which data is scarce (consider a problem with , say), we'd like to do something better.
Here is a method, called -fold cross validation, that holds out less data each time:
- Randomly split
into disjoint subsets of training examples each. Lets call these subsets . - For each model
, we evaluate it as follows: - Pick the model
with the lowest estimated generalization error, and retrain that model on the entire training set . The resulting hypothesis is then output as our final answer.
- For
- Train the model
A typical choice for the number of folds to use here would be . While the fraction of data held out each time is now –much smaller than before–this procedure may also be more computationally expensive than hold-out cross validation, since we now need train to each model times.
While is a commonly used choice, in problems in which data is really scarce, sometimes we will use the extreme choice of in order to leave out as little data as possible each time. In this setting, we would repeatedly train on all but one of the training examples in , and test on that held-out example. The resulting errors are then averaged together to obtain our estimate of the generalization error of a model. This method has its own name; since we're holding out one training example at a time, this method is called leave-one-out cross validation.
Finally, even though we have described the different versions of cross validation as methods for selecting a model, they can also be used more simply to evaluate a single model or algorithm. For example, if you have implemented some learning algorithm and want to estimate how well it performs for your application (or if you have invented a novel learning algorithm and want to report in a technical paper how well it performs on various test sets), cross validation would give a reasonable way of doing so.
2. Feature Selection
One special and important case of model selection is called feature selection. To motivate this, imagine that you have a supervised learning problem where the number of features is very large (perhaps ), but you suspect that there is only a small number of features that are "relevant" to the learning task. Even if you use the a simple linear classifier (such as the perceptron) over the input features, the VC dimension of your hypothesis class would still be , and thus overfitting would be a potential problem unless the training set is fairly large.
In such a setting, you can apply a feature selection algorithm to reduce the number of features. Given features, there are possible feature subsets (since each of the features can either be included or excluded from the subset), and thus feature selection can be posed as a model selection problem over possible models. For large values of , it's usually too expensive to explicitly enumerate over and compare all models, and so typically some heuristic search procedure is used to find a good feature subset. The following search procedure is called forward search:
- Initialize
. - Repeat
- (a)For
if , let , and use some version of cross validation to evaluate features . (I.e., train your learning algorithm using only the features in , and estimate its generalization error.) - (b)Set
to be the best feature subset found on step (a). - Select and output the best feature subset that was evaluated during the entire search procedure.
The outer loop of the algorithm can be terminated either when is the set of all features, or when exceeds some pre-set threshold (corresponding to the maximum number of features that you want the algorithm to consider using).
This algorithm described above one instantiation of wrapper model feature selection, since it is a procedure that "wraps" around your learning algorithm, and repeatedly makes calls to the learning algorithm to evaluate how well it does using different feature subsets. Aside from forward search, other search procedures can also be used. For example, backward search starts off with as the set of all features, and repeatedly deletes features one at a time (evaluating single-feature deletions in a similar manner to how forward search evaluates single-feature additions) until .
Wrapper feature selection algorithms often work quite well, but can be computationally expensive given how that they need to make many calls to the learning algorithm. Indeed, complete forward search (terminating when would take about calls to the learning algorithm.
Filter feature selection methods give heuristic, but computationally much cheaper, ways of choosing a feature subset. The idea here is to compute some simple score that measures how informative each feature is about the class labels . Then, we simply pick the features with the largest scores .
One possible choice of the score would be define to be (the absolute value of) the correlation between and , as measured on the training data. This would result in our choosing the features that are the most strongly correlated with the class labels. In practice, it is more common (particularly for discrete-valued features ) to choose to be the mutual information between and :
(The equation above assumes that and are binary-valued; more generally the summations would be over the domains of the variables.) The probabilities above and can all be estimated according to their empirical distributions on the training set.
To gain intuition about what this score does, note that the mutual information can also be expressed as a Kullback-Leibler (KL) divergence:
You'll get to play more with KL-divergence in Problem set #3, but informally, this gives a measure of how different the probability distributions and are. If and are independent random variables, then we would have , and the KL-divergence between the two distributions will be zero. This is consistent with the idea if and are independent, then is clearly very "non-informative" about , and thus the score should be small. Conversely, if is very "informative" about , then their mutual information would be large.
One final detail: Now that you've ranked the features according to their scores , how do you decide how many features to choose? Well, one standard way to do so is to use cross validation to select among the possible values of . For example, when applying naive Bayes to text classification–a problem where , the vocabulary size, is usually very large–using this method to select a feature subset often results in increased classifier accuracy.
3. Bayesian statistics and regularization
In this section, we will talk about one more tool in our arsenal for our battle against overfitting.
At the beginning of the quarter, we talked about parameter fitting using maximum likelihood estimation (MLE), and chose our parameters according to
Throughout our subsequent discussions, we viewed as an unknown parameter of the world. This view of the as being constant-valued but unknown is taken in frequentist statistics. In the frequentist this view of the world, is not random–it just happens to be unknown–and it's our job to come up with statistical procedures (such as maximum likelihood) to try to estimate this parameter.
An alternative way to approach our parameter estimation problems is to take the Bayesian view of the world, and think of as being a random variable whose value is unknown. In this approach, we would specify a prior distribution on that expresses our "prior beliefs" about the parameters. Given a training set , when we are asked to make a prediction on a new value of , we can then compute the posterior distribution on the parameters
In the equation above, comes from whatever model you're using for your learning problem. For example, if you are using Bayesian logistic regression, then you might choose , where .[3]
When we are given a new test example and asked to make it prediction on it, we can compute our posterior distribution on the class label using the posterior distribution on :
In the equation above, comes from Equation (1). Thus, for example, if the goal is to the predict the expected value of given , then we would output[4]
The procedure that we've outlined here can be thought of as doing "fully Bayesian" prediction, where our prediction is computed by taking an average with respect to the posterior over . Unfortunately, in general it is computationally very difficult to compute this posterior distribution. This is because it requires taking integrals over the (usually high-dimensional) as in Equation (1), and this typically cannot be done in closed-form.
Thus, in practice we will instead approximate the posterior distribution for . One common approximation is to replace our posterior distribution for (as in Equation 2) with a single point estimate. The MAP (maximum a posteriori) estimate for is given by
Note that this is the same formulas as for the MLE (maximum likelihood) estimate for , except for the prior term at the end.
In practical applications, a common choice for the prior is to assume that . Using this choice of prior, the fitted parameters will have smaller norm than that selected by maximum likelihood. (See Problem Set #3.) In practice, this causes the Bayesian MAP estimate to be less susceptible to overfitting than the ML estimate of the parameters. For example, Bayesian logistic regression turns out to be an effective algorithm for text classification, even though in text classification we usually have .
You can read the notes from the next lecture from Andrew Ng's CS229 course on the k-means clustering algorithm here.
- Given that we said in the previous set of notes that bias and variance are two very different beasts, some readers may be wondering if we should be calling them "twin" evils here. Perhaps it'd be better to think of them as non-identical twins. The phrase "the fraternal twin evils of bias and variance" doesn't have the same ring to it, though. ↩︎
- If we are trying to choose from an infinite set of models, say corresponding to the possible values of the bandwidth
, we may discretize and consider only a finite number of possible values for it. More generally, most of the algorithms described here can all be viewed as performing optimization search in the space of models, and we can perform this search over infinite model classes as well. ↩︎ - Since we are now viewing
as a random variable, it is okay to condition on it value, and write " " instead of " ." ↩︎ - The integral below would be replaced by a summation if
is discrete-valued. ↩︎
Recommended for you
High Dimension Data Analysis - A tutorial and review for Dimensionality Reduction Techniques
High Dimension Data Analysis - A tutorial and review for Dimensionality Reduction Techniques
This article explains and provides a comparative study of a few techniques for dimensionality reduction. It dives into the mathematical explanation of several feature selection and feature transformation techniques, while also providing the algorithmic representation and implementation of some other techniques. Lastly, it also provides a very brief review of various other works done in this space.