








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!









Optional Readings: Berk, chapter 2.
1 What Are Statistical Models For? Summaries, Forecasts, Sim- ulators 1
2 Errors, In and Out of Sample 3
3 Over-Fitting and Model Selection 5
4 Cross-Validation 11 4.1 Data-set Splitting........................... 11 4.2 Cross-Validation (CV)........................ 12 4.3 Leave-one-out Cross-Validation................... 12
5 Warnings 13
6 Exercises 13
There are (at least) three levels at which we can use statistical models in data analysis: as summaries of the data, as predictors, and as simulators. The lowest and least demanding level is just to use the model as a summary of the data — to use it for data reduction, or compression. Just as one can use the sample mean or sample quantiles as descriptive statistics, recording some features of the data and saying nothing about a population or a gener- ative process, we could use estimates of a model’s parameters as descriptive summaries. Rather than remembering all the points on a scatter-plot, say, we’d just remember what the OLS regression surface was. It’s hard to be wrong about a summary, unless we just make a mistake. (It may or may not be helpful for us later, but that’s different.) When we say “the
slope which best fit the training data was ˆb = 4.02”, we make no claims about anything but the training data. It relies on no assumptions, beyond our doing the calculations right. But it also asserts nothing about the rest of the world. As soon as we try to connect our training data to the rest of the world, we start relying on assumptions, and we run the risk of being wrong. Probably the most common connection to want to make is to say what other data will look like — to make predictions. In a statistical model, with random noise terms, we do not anticipate that our predictions will ever be exactly right, but we also anticipate that our mistakes will show stable probabilistic patterns. We can evaluate predictions based on those patterns of error — how big is our typical mistake? are we biased in a particular direction? do we make a lot of little errors or a few huge ones? Statistical inference about model parameters — estimation and hypothesis testing — can be seen as a kind of prediction, extrapolating from what we saw in a small piece of data to what we would see in the whole population, or whole process. When we estimate the regression coefficient ˆb = 4.02, that involves predicting new values of the dependent variable, but also predicting that if we repeated the experiment and re-estimated ˆb, we’d get a value close to 4.02. Using a model to summarize old data, or to predict new data, doesn’t commit us to assuming that the model describes the process which generates the data. But we often want to do that, because we want to interpret parts of the model as aspects of the real world. We think that in neighborhoods where people have more money, they spend more on houses — perhaps each extra $1000 in income translates into an extra $4020 in house prices. Used this way, statistical models become stories about how the data were generated. If they are accurate, we should be able to use them to simulate that process, to step through it and produce something that looks, probabilistically, just like the actual data. This is often what people have in mind when they talk about scientific models, rather than just statistical ones. An example: if you want to predict where in the night sky the planets will be, you can actually do very well with a model where the Earth is at the center of the universe, and the Sun and everything else revolve around it. You can even estimate, from data, how fast Mars (for example) goes around the Earth, or where, in this model, it should be tonight. But, since the Earth is not at the center of the solar system, those parameters don’t actually refer to anything in reality. They are just mathematical fictions. On the other hand, we can also predict where the planets will appear in the sky using models where all the planets orbit the Sun, and the parameters of the orbit of Mars in that model do refer to reality.^1 We are going to focus today on evaluating predictions, for three reasons. First, often we just want prediction. Second, if a model can’t even predict well, it’s hard to see how it could be right scientifically. Third, often the best way of checking a scientific model is to turn some of its implications into statistical
(^1) We can be pretty confident of this, because we use our parameter estimates to send our robots to Mars, and they get there.
the origin of the variance term in the bias-variance decomposition. But as we get more and more data, the sample should become more and more representative of the whole process, and estimates should converge too.
So, because our models are flawed, we have limited data and the world is stochas- tic, we cannot expect even the best model to have zero error. Instead, we would like to minimize the expected error, or risk, or generalization error, on new data. What we would like to do is to minimize the risk or expected loss
E [L(Z, θ)] =
dzp(z)L(z, θ)
To do this, however, we’d have to be able to calculate that expectation. Doing that would mean knowing the distribution of Z — the joint distribution of X and Y , for the regression problem. Since we don’t know the true joint distribution, we need to approximate it somehow. A natural approximation is to use our training data zn. For each possible model θ, we can could calculate the error on the data, L(zn, θ), called the in- sample loss or the empirical risk. The simplest strategy for estimation is then to pick the model, the value of θ, which minimizes the in-sample loss. This strategy is imaginatively called empirical risk minimization. Formally,
̂ θn ≡ argmin θ∈Θ
L(zn, θ)
This means picking the regression which minimizes the sum of squared errors, or the density with the highest likelihood^4. This what you’ve usually done in statistics courses so far, and it’s very natural, but it does have some issues, notably optimism and over-fitting. The problem of optimism comes from the fact that our training data isn’t perfectly representative. The in-sample loss is a sample average. By the law of large numbers, then, we anticipate that, for each θ,
L(zn, θ) → E [L(Z, θ)] (^3) Except maybe in fundamental physics, and even there our predictions are about our fundamental theories in the context of experimental set-ups, which we never model in complete detail. (^4) Remember, maximizing the likelihood is the same as maximizing the log-likelihood, be- cause log is an increasing function. Therefore maximizing the likelihood is the same as mini- mizing the negative log-likelihood.
as n → ∞. This means that, with enough data, the in-sample error is a good approximation to the generalization error of any given model θ. (Big samples are representative of the underlying population or process.) But this does not mean that the in-sample performance of θˆ tells us how well it will generalize, because we purposely picked it to match the training data zn. To see this, notice that the in-sample loss equals the risk plus sampling noise:
L(zn, θ) = E [L(Z, θ)] + ηn(θ) (1)
Here η(θ) is a random term which has mean zero, and represents the effects of having only a finite quantity of data, of size n, rather than the complete probability distribution. (I write it ηn(θ) as a reminder that different models are going to be affected differently by the same sampling fluctuations.) The problem, then, is that the model which minimizes the in-sample loss could be one with good generalization performance (E [L(Z, θ)] is small), or it could be one which got very lucky (ηn(θ) was large and negative):
̂ θn = argmin θ∈Θ
(E [L(Z, θ)] + ηn(θ)) (2)
We only want to minimize E [L(Z, θ)], but we can’t separate it from ηn(θ), so
we’re almost surely going to end up picking a ̂θn which was more or less lucky (ηn < 0) as well as good (E [L(Z, θ)] small). This is the reason why picking the model which best fits the data tends to exaggerate how well it will do in the future. Again, by the law of large numbers ηn(θ) → 0 for each θ, but now we need to worry about how fast it’s going to zero, and whether that rate depends on θ. Suppose we knew that minθ ηn(θ) → 0, or maxθ |ηn(θ)| → 0. Then it would follow that ηn(̂ θn) → 0, and the over-optimism in using the in-sample error to approximate the generalization error would at least be shrinking. If we knew how fast maxθ |ηn(θ)| was going to zero, we could even say something about how much bigger the true risk was likely to be. A lot of more advanced statistics and machine learning theory is thus about uniform laws of large numbers (showing maxθ |ηn(θ)| → 0) and rates of convergence. Learning theory is a beautiful, deep, and practically important subject, but also subtle and involved one.^5 To stick closer to analyzing real data, and to not turn this into an advanced probability class, I will only talk about some more-or-less heuristic methods, which are good enough for many purposes.
The big problem with using the in-sample error is related to over-optimism, but at once trickier to grasp and more important. This is the problem of over- fitting. To illustrate it, let’s start with Figure 1. This has the twenty X values (^5) Some comparatively easy starting points are Kearns and Vazirani (1994) or Cristianini and Shawe-Taylor (2000). At a more advanced level, look at the tutorial papers by Bousquet et al. (2004); von Luxburg and Sch¨olkopf (2008), or the textbook by Vidyasagar (2003), or read the book by Vapnik (2000) (one of the founders), or take the class 10-702.
-2 -1 0 1 2
0
10
20
30
40
50
x
y
plot(x,y2) curve(7x^2-0.5x,add=TRUE,col="grey")
Figure 1: Scatter-plot showing sample data and the true, quadratic regression curve (grey parabola).
-2 -1 0 1 2
0
10
20
30
40
50
x
y
y2.0 = lm(y2 ~ 1) abline(h=y2.0$coefficients[1]) d = seq(-2,2,length.out=200) for (degree in 1:9) { fm = lm(y2 ~ poly(x,degree)) assign(paste("y2",degree,sep="."), fm) lines(d, predict(fm,data.frame(x=d)),lty=(degree+1)) }
Figure 2: Twenty training data points (dots), and ten different fitted regression lines (polynomials of order 0 to 9, indicated by different line types). R notes: The poly command constructs orthogonal (uncorrelated) polynomials of the specified degree from its first argument; regressing on them is conceptually equivalent to re- gressing on 1, x, x^2 ,... xdegree, but more numerically stable. (See help(poly).) This use of the assign and paste functions together is helpful for storing results which don’t fit well into arrays.
0 2 4 6 8
polynomial degree
mean squared error
gmse.q = vector(length=10) for (degree in 0:9) { fm = get(paste("y",degree,sep=".")) predictions = predict(fm,data.frame(x=x.new)) resids = y.new - predictions gmse.q[degree+1] = mean(resids^2) } plot(0:9,mse.q,type="b",xlab="polynomial degree", ylab="mean squared error",log="y",ylim=c(min(mse.q),max(gmse.q))) lines(0:9,gmse.q,lty=2,col="blue") points(0:9,gmse.q,pch=24,col="blue")
Figure 4: In-sample error (black dots) compared to generalization error (blue triangles). Note the logarithmic scale for the vertical axis.
There is nothing special about polynomials here. All of the same lessons apply to variable selection in linear regression, to k-nearest neighbors (where we need to choose k), to kernel regression (where we need to choose the bandwidth), and to other methods we’ll see later. In every case, there is going to be a minimum for the generalization error curve, which we’d like to find. (A minimum with respect to what, though? In Figure 4, the horizontal axis is the model order, which here is the number of parameters (minus one). More generally, however, what we care about is some measure of how complex the model space is, which is not necessarily the same thing as the number of pa- rameters. What’s more relevant is how flexible the class of models is, how many different functions it can approximate. Linear polynomials can approximate a smaller set of functions than quadratics can, so the latter are more complex, or have higher capacity. More advanced learning theory has a number of ways of quantifying this, but the details are pretty arcane, so we will just use the concept of complexity or capacity informally.)
The most straightforward way to find the generalization error would be to do what I did above, and to use fresh, independent data from the same source — a testing or validation data-set. Call this z′ m, as opposed to our training data zn. We fit our model to zn, and get θ̂n. The loss of this on the validation data is E
L(Z, ̂θn)
where now the sampling noise on the validation set, η′ m, is independent of θ̂m. So this gives us an unbiased estimate of the generalization error, and, if m is large, a precise one. If we need to select one model from among many, we can pick the one which does best on the validation data, with confidence that we are not just over-fitting. The problem with this approach is that we absolutely, positively, cannot use any of the validation data in estimating the model. Since collecting data is expensive — it takes time, effort, and usually money, organization and skill — this means getting a validation data set is expensive, and we often won’t have that luxury.
The next logical step, however, is to realize that we don’t strictly need a separate validation set. We can just take our data and split it ourselves into training and testing sets. If we divide the data into two parts at random, we ensure that they have (as much as possible) the same distribution, and that they are independent of each other. Then we can act just as though we had a real validation set. Fitting to one part of the data, and evaluating on the other, gives us an unbiased estimate of generalization error.
doing calculations on a model fit to the whole data. This means that we only have to fit each model once, rather than k times, which can be a big savings of computing time. The drawback to leave-one-out CV is subtle but often decisive. Since each training set has n − 1 points, any two training sets must share n − 2 points. The models fit to those training sets tend to be strongly correlated with each other. Even though we are averaging n out-of-sample forecasts, those are correlated forecasts, so we are not really averaging away all that much noise. With k-fold CV, on the other hand, the fraction of data shared between any two training sets is just k k−−^21 , not n n−−^21 , so even though the number of terms being averaged is smaller, they are less correlated. There are situations where this issue doesn’t really matter, or where it’s overwhelmed by leave-one-out’s advantages in speed and simplicity, so there is certainly still a place for it, but one subordinate to k-fold CV.
Some caveats are in order.
To think through, not to hand in.
Bousquet, Olivier, St´ephane Boucheron and G´abor Lugosi (2004). “Introduction to Statistical Learning Theory.” In Advanced Lectures in Machine Learning (Olivier Bousquet and Ulrike von Luxburg and Gunnar R¨atsch, eds.), pp. 169–
Cristianini, Nello and John Shawe-Taylor (2000). An Introduction to Support Vector Machines: And Other Kernel-Based Learning Methods. Cambridge, England: Cambridge University Press.
Kearns, Michael J. and Umesh V. Vazirani (1994). An Introduction to Compu- tational Learning Theory. Cambridge, Massachusetts: MIT Press.
Qui˜nonero-Candela, Joaquin, Masashi Sugiyama, Anton Schwaighofer and Neil D. Lawrence (eds.) (2009). Dataset Shift in Machine Learning. Cam- bridge, Massachusetts: MIT Press.
Vapnik, Vladimir N. (2000). The Nature of Statistical Learning Theory. Berlin: Springer-Verlag, 2nd edn.
Vidyasagar, M. (2003). Learning and Generalization: With Applications to Neural Networks. Berlin: Springer-Verlag, 2nd edn.
von Luxburg, Ulrike and Bernhard Sch¨olkopf (2008). “Statistical Learning Theory: Models, Concepts, and Results.” E-print, arxiv.org. URL http: //arxiv.org/abs/0810.4752.