Here are my notes regarding Chapter 2 of The elements of statistical learning: data mining, inference and prediction.
This chapter illustrates many useful concepts in statistics using two simple models as example. It compares the performance of linear models fitted through least square technique with the -nearest-neighbor method, where the prediction is given by the average of the nearest neighbors response values.
Effective number of parameters
At first, it might seem that -nearest-neighbor fits have a single parameter, the number of neighbors , compared to the parameters in least-squares fits (with -dimensional input). Although this is the case, it will be formalized later in the book that the effective number of parameters of -nearest neighbors is , which is generally bigger than , and decreases with increasing . To get an idea of why, note that if the neighborhoods were non-overlapping, there would be neighborhoods and we would fit one parameter (a mean) in each neighborhood.
Expected prediction error and Squared loss function
Usually, in our data analysis problems, we seek a function for predicting , given values of the -dimensional input .
It was shown that under squared error loss, the expected prediction error,
taken wrt the joint distribution , is minimized by . Thus the best prediction of at any point is the conditional mean, when best is measured by average squared error.
Both -nearest neighbors and least squares end up approximating conditional expectations by averages. But they differ dramatically in terms of model assumptions:
- Least squares assumes is well approximated by a globally linear function.
- -nearest neighbors assumes is well approximated by a locally constant function.
Looking at this difference, we might feel that least squares is very restrictive while the -nearest neighbors are more flexible and can always adapts well for a particular problem when given enough data points. In fact, under mild regularity conditions on the joint probability distribution , one can show that as such that , . In light of this, why look further, since it seems we have a universal approximator?
Limited sample sizes
First of all we often do not have very large samples. If the linear or some more structured model is appropriate, then we can usually get a more stable estimate than -nearest neighbors, although such knowledge has to be learned from the data as well. There are other problems though, sometimes disastrous. Even when we think we have a very large sample size, we might be mistaken. For example we might face the curse of dimensionality.
Curse of dimensionality
It would seem that with a reasonably large set of training data, we could always approximate the theoretically optimal conditional expectation by -nearest-neighbor averaging, since we should be able to find a fairly large neighborhood of observations close to any and average them. This approach and our intuition breaks down in high dimensions, and the phenomenon is commonly referred to as the curse of dimensionality (Bellman, 1961).
There are many manifestations of this problem, and a few of them were described:
- Consider the nearest-neighbor procedure for inputs uniformly distributed in a -dimensional unit hypercube. To capture 1% or 10% of the data to form a local average with , we must cover 63% or 80% of the range of each input variable. Such neighborhoods are no longer “local”. Reducing the percentage of the data covered dramatically does not help much either, since the fewer observations we average, the higher is the variance of our fit.
- Consider data points uniformly distributed in a -dimensional unit ball centered at the origin. A formula to compute the median distance from the origin to the closest data point was given. It was shown that most data points are closer to the boundary of the sample space than to any other data point, and this gets worse as increases. The reason that this presents a problem is that prediction is much more difficult near the edges of the training sample. One must extrapolate from neighboring sample points rather than interpolate between them.
- Another manifestation of the curse is that the sampling density is proportional to , where is the dimension of the input space and is the sample size. Thus, if represents a dense sample for a single input problem, then is the sample size required for the same sampling density with inputs. Thus in high dimensions all feasible training samples sparsely populate the input space.
Going back to our objective of estimating the function to predict for a given -dimensional input, the curse of dimensionality states that the complexity of functions of many variables can grow exponentially with the dimension, and if we wish to be able to estimate such functions with the same accuracy as function in low dimensions, then we need the size of our training set to grow exponentially as well.
By imposing some heavy restrictions on the class of models being fitted, we can avoid the curse of dimensionality.
Structured Regression Models
Although nearest-neighbor and other local methods focus directly on estimating the function at a point, they face problems in high-dimensions. They may also be inappropriate even in low dimensions in cases where more structured approaches can make more efficient use of the data.
The choice of finding a function to predict , by minimizing the residual sum of squares (RSS) for example, can have infinitely many solutions. In order to obtain useful results for finite , we must restrict the eligible solutions to a smaller set of functions. These restricted classes of solutions are the major topic of the book. One thing should be clear, though. Any restrictions imposed on that lead to a unique solution to our task do not really remove the ambiguity caused by the multiplicity of solutions. There are infinitely many possible restrictions, each leading to a unique solution, so the ambiguity has simply been transferred to the choice of constraint.
Any method that attempts to produce locally varying functions in small isotropic neighborhoods will run into problems in high dimensions, again the curse of dimensionality. And conversely, all methods that overcome the dimensionality problems have an associated, and often implicit or adaptive, metric for measuring neighborhoods, which basically does not allow the neighborhood to be simultaneously small in all directions.
Classes of Restricted Estimators
The variety of nonparametric regression techniques or learning methods fall into a number of different classes depending on the nature of the restrictions imposed. These classes are not distinct, and indeed some methods fall in several classes. Each of the classes has associated with it one or more parameters, sometimes appropriately called smoothing parameters, that control the effective size of the local neighborhood. In the book they describe three broad classes.
- Roughness Penalty and Bayesian Methods: Here the class of functions is controlled by explicitly penalizing with a roughness penalty
The user-selected functional will be large for functions that vary too rapidly over small regions of input space. Penalty function, or regularization methods, express our prior belief that the type of functions we seek exhibit a certain type of smooth behavior, and indeed can usually be cast in a Bayesian framework.
- Kernel Methods and Local Regression: These methods can be thought of as explicitly providing estimates of the regression function or conditional expectation by specifying the nature of the local neighborhood, and of the class of regular functions fitted locally. The local neighborhood is specified by a kernel function which assigns weights to points in a region around . In general we can define a local regression estimate of as , where minimizes
and is some parameterized function, such as a low-order polynomial.
- Basis Functions and Dictionary Methods: The model for is a linear expansion of basis functions
where each of the is a function of the input , and the term linear here refers to the action of the parameters . Adaptively chosen basis function methods are also known as dictionary methods, where one has available a possibly infinite set or dictionary of candidate basis functions from which to choose, and models are built up by employing some kind of search mechanism.
Expected prediction error for categorical variable
What do we do when the output is a categorical variable ? Our loss function can be represented by a matrix , where . will be zero on the diagonal and non-negative elsewhere, where is the price paid for classifying an observation belonging to class as . Most often we use the zero-one loss function, where all misclassifications are charged a single unit.
With this loss function the solution that minimizes the expected prediction error is
This reasonable solution is known as the Bayes classifier, and says that we classify to the most probable class, using the conditional (discrete) distribution . The error rate of the Bayes classifier is called the Bayes rate.
The email/spam example illustrate well the point that in a statistical problem not all the errors are necessarily equal. We want to avoid filtering out good email, while letting spam get through is not desirable but less serious in its consequences.
The linear decision boundary from least squares is very smooth, and apparently stable to fit. It does appear to rely heavily on the assumption that a linear decision boundary is appropriate. It has low variance and potentially high bias. On the other hand, the -nearest-neighbor procedures do not appear to rely on any stringent assumptions about the underlying data, and can adapt to any situation. However, any particular sub-region of the decision boundary depends on a handful of input points and their particular positions, and is thus wiggly and unstable, i.e. high variance and low bias. Each method has its own situations for which it works best.
Typically we would like to choose our model complexity to trade bias off with variance in such a way as to minimize the test error. An obvious estimate of test error is the training error . Unfortunately, training error is not a good estimate of test error, as it does not properly account for model complexity. Increasing the complex of the model will alaways give you better training error. Figure 2.11 of the book shows the typical behavior of the test and training error, as model complexity is varied.
Chapter 7 of the book will discuss methods for estimating the test error of a prediction method, and hence estimating the optimal amount of model complexity for a given prediction method and training set.
– Hastie, T., Tibshirani, R., Friedman, J. (2009). The elements of statistical learning: data mining, inference and prediction. Springer. (Chapter 2)
– Bellman, R. E. (1961). Adaptive Control Processes, Princeton University Press.