





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Recall that as discussed in Section 8.1, overfitting is typically a result of us- ing too complex models, and we need to choose a proper model complexity to achieve the optimal bias-variance tradeoff. When the model complexity is measured by the number of parameters, we can vary the size of the model (e.g., the width of a neural net). However, the correct, informative complex- ity measure of the models can be a function of the parameters (e.g., ` 2 norm of the parameters), which may not necessarily depend on the number of pa- rameters. In such cases, we will use regularization, an important technique in machine learning, to control the model complexity and prevent overfitting. Regularization typically involves adding an additional term, called a reg- ularizer and denoted by R(θ) here, to the training loss/cost function:
Jλ(θ) = J(θ) + λR(θ) (9.1)
Here Jλ is often called the regularized loss, and λ ≥ 0 is called the regular- ization parameter. The regularizer R(θ) is a nonnegative function (in almost all cases). In classical methods, R(θ) is purely a function of the parameter θ, but some modern approach allows R(θ) to depend on the training dataset.^1 The regularizer R(θ) is typically chosen to be some measure of the com- plexity of the model θ. Thus, when using the regularized loss, we aim to find a model that both fit the data (a small loss J(θ)) and have a small
(^1) Here our notations generally omit the dependency on the training dataset for
simplicity—we write J(θ) even though it obviously needs to depend on the training dataset.
model complexity (a small R(θ)). The balance between the two objectives is controlled by the regularization parameter λ. When λ = 0, the regularized loss is equivalent to the original loss. When λ is a sufficiently small positive number, minimizing the regularized loss is effectively minimizing the original loss with the regularizer as the tie-breaker. When the regularizer is extremely large, then the original loss is not effective (and likely the model will have a large bias.) The most commonly used regularization is perhaps 2 regularization, where R(θ) = 12 ‖θ‖^22. It encourages the optimizer to find a model with small 2 norm. In deep learning, it’s oftentimes referred to as weight de- cay, because gradient descent with learning rate η on the regularized loss Rλ(θ) is equivalent to shrinking/decaying θ by a scalar factor of 1 − ηλ and then applying the standard gradient
θ ← θ − η∇Jλ(θ) = θ − ηλθ − η∇J(θ) = (1 − λη)θ ︸ ︷︷ ︸ decaying weights
−η∇J(θ) (9.2)
Besides encouraging simpler models, regularization can also impose in- ductive biases or structures on the model parameters. For example, suppose we had a prior belief that the number of non-zeros in the ground-truth model parameters is small,^2 —which is oftentimes called sparsity of the model—, we can impose a regularization on the number of non-zeros in θ, denoted by ‖θ‖ 0 , to leverage such a prior belief. Imposing additional structure of the parameters narrows our search space and makes the complexity of the model family smaller,—e.g., the family of sparse models can be thought of as having lower complexity than the family of all models—, and thus tends to lead to a better generalization. On the other hand, imposing additional structure may risk increasing the bias. For example, if we regularize the sparsity strongly but no sparse models can predict the label accurately, we will suffer from large bias (analogously to the situation when we use linear models to learn data than can only be represented by quadratic functions in Section 8.1.) The sparsity of the parameters is not a continuous function of the param- eters, and thus we cannot optimize it with (stochastic) gradient descent. A common relaxation is to use R(θ) = ‖θ‖ 1 as a continuous surrogate.^3
(^2) For linear models, this means the model just uses a few coordinates of the inputs to make an accurate prediction. (^3) There has been a rich line of theoretical work that explains why ‖θ‖ 1 is a good sur- rogate for encouraging sparsity, but it’s beyond the scope of this course. An intuition is: assuming the parameter is on the unit sphere, the parameter with smallest ` 1 norm also
θ
loss
Figure 9.1: An Illustration that different global minima of the training loss can have different test performance.
Figure 9.2: Left: Performance of neural networks trained by two different learning rates schedules on the CIFAR-10 dataset. Although both exper- iments used exactly the same regularized losses and the optimizers fit the training data perfectly, the models’ generalization performance differ much. Right: On a different synthetic dataset, optimizers with different initializa- tions have the same training error but different generalization performance.^4
In summary, the takehome message here is that the choice of optimizer does not only affect minimizing the training loss, but also imposes implicit regularization and affects the generalization of the model. Even if your cur- rent optimizer already converges to a small training error perfectly, you may still need to tune your optimizer for a better generalization,.
(^4) The setting is the same as in Woodworth et al. [2020], HaoChen et al. [2020]
One may wonder which components of the optimizers bias towards what type of global minima and what type of global minima may generalize bet- ter. These are open questions that researchers are actively investigating. Empirical and theoretical research have offered some clues and heuristics. In many (but definitely far from all) situations, among those setting where optimization can succeed in minimizing the training loss, the use of larger initial learning rate, smaller initialization, smaller batch size, and momen- tum appears to help with biasing towards more generalizable solutions. A conjecture (that can be proven in certain simplified case) is that stochas- ticity in the optimization process help the optimizer to find flatter global minima (global minima where the curvature of the loss is small), and flat global minima tend to give more Lipschitz models and better generalization. Characterizing the implicit regularization effect formally is still a challenging open research question.
Suppose we are trying select among several different models for a learning problem. For instance, we might be using a polynomial regression model hθ(x) = g(θ 0 + θ 1 x + θ 2 x^2 + · · · + θkxk), and wish to decide if k should be 0, 1,... , or 10. How can we automatically select a model that represents a good tradeoff between the twin evils of bias and variance^5? Alternatively, suppose we want to automatically choose the bandwidth parameter τ for locally weighted regression, or the parameter C for our ` 1 -regularized SVM. How can we do that? For the sake of concreteness, in these notes we assume we have some finite set of models M = {M 1 ,... , Md} that we’re trying to select among. For instance, in our first example above, the model Mi would be an i-th degree polynomial regression model. (The generalization to infinite M is not hard.^6 ) Alternatively, if we are trying to decide between using an SVM, a neural network or logistic regression, then M may contain these models.
(^5) 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. (^6) If we are trying to choose from an infinite set of models, say corresponding to the
possible values of the bandwidth τ ∈ R+, 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.
conditions and/or data. For these methods, Mi doing well on Strain does not necessarily mean it will also do well on Scv, and it might be better to forgo this retraining step.) The disadvantage of using hold out cross validation is that it “wastes” about 30% 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 0. 7 n training examples, rather than n training examples, since we’re testing models that were trained on only 0. 7 n 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 n = 20, say), we’d like to do something better. Here is a method, called k-fold cross validation, that holds out less data each time:
For j = 1,... , k Train the model Mi on S 1 ∪ · · · ∪ Sj− 1 ∪ Sj+1 ∪ · · · Sk (i.e., train on all the data except Sj ) to get some hypothesis hij. Test the hypothesis hij on Sj , to get ˆεSj (hij ). The estimated generalization error of model Mi is then calculated as the average of the ˆεSj (hij )’s (averaged over j).
A typical choice for the number of folds to use here would be k = 10. While the fraction of data held out each time is now 1/k—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 k times. While k = 10 is a commonly used choice, in problems in which data is really scarce, sometimes we will use the extreme choice of k = m 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 S, and test on that held-out example. The resulting m = k 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 vali- dation 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.
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
θMLE = arg max θ
∏n
i=
p(y(i)|x(i); θ).
Throughout our subsequent discussions, we viewed θ as an unknown param- eter 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 p(θ) on θ that expresses our “prior beliefs” about the parameters. Given a training set S = {(x(i), y(i))}ni=1, when we are asked to make a prediction on a new value of x, we can then compute the posterior distribution on the parameters
p(θ|S) =
p(S|θ)p(θ) p(S)
=
(∏n i=1 p(y
(i)|x(i), θ))^ p(θ) ∫ θ (
∏n i=1 p(y (i)|x(i), θ)p(θ)) dθ (9.3)
In the equation above, p(y(i)|x(i), θ) comes from whatever model you’re using