MIT 6.790 — Lecture 7
Kernels, Evaluations, and Hyperparameter Learning
§ Kernels: Properties and Examples
Problem. Suppose our input space is , and our kernel is via . What feature map is represented by this kernel, and what is the implied feature dimension?
Solution: Given inputs and , the kernel can be expressed as:
Having “decoupled” the kernel in this way, it is now clear that the feature map is , and the implied feature dimension is . (More generally, the implied feature dimension is the “number of terms” in the kernel.)
To really emphasize how much cleaner kernels are to work with than features, here's a much larger example.
Problem. Suppose our input space is , and our kernel is via . What is the implied feature dimension? Compare the difficulty of computing the matrices versus (using the notation from Lecture 6).
Solution: The feature dimension is the “number of terms” in the expansion of . This is equivalent to the number of monomials of degree in variables, which (by Stars and Bars) is:
Now for the computational difficulty comparisons.
Computing costs .
We need the values across all pairs of inputs , and computing each value takes .
Computing costs .
This bound comes from the space of , alone: the dimensions of are .
Evidently, it is much more convenient to work with kernels than it is to work with features.
And it turns out that kernels do everything that features can do.
Theorem. (Mercer's Theorem) If, for every choice of inputs , the kernel matrix is symmetric and positive semidefinite, and the kernel is continuous, then corresponds to some feature map .
The proof is fairly nontrivial, so we omit it. The upshot is that we can now declare any kernel we'd like (so long as it satisfies the conditions of Mercer's theorem), and we need not have any concern for what features are involved.
Remark. If we can choose kernels arbitrarily, that raises the question: what makes one choice of kernel better than another?
Here's one possible answer, from the “feature” perspective.
Answer 1. The kernel ultimately describes a collection of features, and a ridge regression models the relationship between and via a linear combination of those features, with preference towards linear combinations with smaller coefficients.
Therefore, a good kernel should imply a collection of features that is capable of modeling the relationship between and using relatively small coefficients.
Here's another possible answer, from the “hypothesis” perspective.
Answer 2. Recall from Lecture 6 that, ultimately, our hypothesis looks like . Expressed component-wise, that looks like:
In other words, is a weighted sum of the , with weights given by . This brings out a sense in which reflects a similarity score between and . The more similar is to , the more impact has on .
The kernel can also be seen as a similarity score by recalling that is just the dot product of and in the feature space . Indeed, if we normalize the kernel so that , then we have
by the Law of Cosines. The similarity score captures the similarity of and as positions in the feature space.
Definition. One common choice of kernel is the Gaussian or RBF kernel, given by:
Note that this kernel has an infinite-dimensional feature map. (All of the work done in the previous lecture works just as well in infinite-dimensional vector spaces, so there's nothing to be worried about.)
§ Recap: Two Approaches to Regression
Let's summarize all that we've discussed about regression so far.
Given some data , there are two approaches to learning a hypothesis .
These two approaches conceptually differ in the following way:
The former involves learning a parameter in the feature space described by .
The latter is a nonparametric definition of a function in a sample space whose behavior depends on the kernel .
Besides their conceptual differences, however, these two approaches are the same: the hypotheses they generate are identical.
§ Learning Algorithms and Hyperparameters
There are two types of objects that appear in the previous section, and it's important to distinguish them clearly.
A hypothesis (or decision rule) (recalling Lecture 1) takes an input and returns a hypothesis .
A learning algorithm takes training data and returns a hypothesis .
In the previous section, the two approaches described are both (the same) learning algorithm, whereas the results produced by these approaches are hypotheses (or decision rules).
Notably, the behavior of the hypothesis , as presented by the first of the two approaches, depends on a parameter . In contrast, the behavior of the learning algorithm depends on a hyperparameter .
§ Evaluating Learning Algorithms
Recall that in Lecture 1 we defined the risk of a hypothesis to be:
where is a loss function of our choice. Note that risk is a property of a hypothesis, not of a learning algorithm—but the risk of a hypothesis can be controlled by carefully setting the hyperparameter of its learning algorithm.
Here's the focus of this section:
Question. How do we evaluate a learning algorithm to determine the best values for its hyperparameters?
As with bootstrapping (discussed in Lecture 13 of 18.650), the idea is to empirically estimate the expected risk of the hypothesis produced, using our own training data as validation data. Stated more precisely:
Randomly partition the data into a training set and a validation set .
Run the learning algorithm on the training set to obtain a hypothesis .
Estimate the risk of this hypothesis to be the average loss across the validation data .
Repeat the previous three steps across many trials, and average the results from step 3 across all trials.
The Law of Large Numbers says that the risk estimates in step 3 will approach the true risk for large , assuming all data is sampled i.i.d. from the same distribution. You can then quantify the (epistemic) uncertainty in the estimate of expected risk produced by step 4 by using basic statistics as well.
Remark. Pay attention to the difference between risk and expected risk.
An iteration of step 3 produces an estimate of the risk of .
Step 4 estimates the expected risk by averaging the risk estimates from step 3 across multiple different hypotheses , each trained on its own training set and evaluated on its own validation set .
Whereas the parameter is evaluated by its risk and learned by the learning algorithm, the hyperparameter is evaluated by its expected risk and learned by us.