Kernel Alignment Risk Estimator: Risk Prediction from Training Data
Arthur Jacot, Berfin Şimşek, Francesco Spadaro, Clément Hongler, Franck Gabriel
Introduction
Kernel Ridge Regression (KRR) is a widely used statistical method to learn a function from its values on a training set . It is a non-parametric generalization of linear regression to infinite-dimensional feature spaces. Given a positive-definite kernel function and (noisy) observations of a true function at a list of points , the -KRR estimator of is defined by
Despite decades of intense mathematical progress, the rigorous analysis of the generalization of kernel methods remains a very active and challenging area of research. In recent years, many new kernels have been introduced for both regression and classification tasks; notably, a large number of kernels have been discovered in the context of deep learning, in particular through the so-called Scattering Transform , and in close connection with deep neural networks , yielding ever-improving performance for various practical tasks . Currently, theoretical tools to select the relevant kernel for a given task, i.e. to minimize the generalization error, are however lacking.
While a number of bounds for the risk of Linear Ridge Regression (LRR) or KRR exist, most focus on the rate of convergence of the risk: these estimates typically involve constant factors which are difficult to control in practice. Recently, a number of more precise estimates have been given ; however, these estimates typically require a priori knowledge of the data distribution. It remains a challenge to have estimates based on the training data alone, enabling one to make informed decisions on the choices of the ridge and of the kernel.
We introduce the Signal Capture Threshold (SCT) , which is determined by the ridge , the size of the training set , the kernel , and the observations distribution (more precisely, the dependence on is only through its first two moments). We give approximations for the expectation and variance of the KRR predictor in terms of the SCT.
Decomposing along the kernel principal components of the data distribution, we observe that in expectation, the predictor captures only the signal along the principal components with eigenvalues larger than the SCT. If increases or decreases, the SCT shrinks, allowing the predictor to capture more signal. At the same time, the variance of scales with the derivative , which grows as , supporting the classical bias-variance tradeoff picture .
We give an explicit approximation for the expected MSE risk and empirical MSE risk for an arbitrary continuous true function . We find that, surprisingly, the expected risk and expected empirical risk are approximately related by
We introduce the Kernel Alignment Risk Estimator (KARE) as the ratio defined by
where is the Gram matrix of on the observations. We show that the KARE approximates the expected risk; unlike the SCT, it is agnostic of the true data distribution. This result follows from the fact that , where is the Stieltjes Transform of the Gram matrix .
Empirically, we find that the KARE predicts the risk on the Higgs and MNIST datasets. We see empirically that our results extend extremely well beyond the Gaussian observation setting, thus supporting our universality assumption (see Figure 1).
Our proofs (see the Appendix) rely on a finite-size analysis of generalized Wishart matrices, in particular the complex Stieltjes transform , evaluated at , and on fixed-point arguments.
2 Related Works
The theoretical analysis of the risk of KRR has seen tremendous developments in the recent years. In particular, a number of upper and lower bounds for kernel risk have been obtained in various settings: notably, convergence rates (i.e. without control of the constant factors) are obtained in general settings. This allows one to abstract away a number of details about the kernels (e.g. the lengthscale), which don’t influence the asymptotic rates. However, this does not give access to the risk at finite data size (crucial to pick e.g. the correct lengthscale or the NTK depth ).
A number of recent results have given precise descriptions of the risk for ridge regression , for random features , and in relation to neural networks . These results rely on the analysis of the asymptotic spectrum of general Wishart random matrices, in particular through the Stieltjes transform . The limiting Stieltjes transform can be recovered from the formula for the product of freely independent matrices . To extend these asymptotic results to finite-size settings, we generalize and adapt the results of .
While these techniques have given simple formulae for the KRR predictor expectation, approximating its variance has remained more challenging. For this reason the description of the expected risk in is stated as a conjecture. In only the bias component of the risk is approximated. In the expected risk is given only for random true functions (in a Bayesian setting) with a specific covariance. In , the expected risk follows from a heuristic spectral analysis combining a PDE approximation and replica tricks. In this paper, we approximate the variance of the predictor along the principal components, giving an approximation of the risk for any continuous true function.
The SCT is related to a number of objects from previous works, such as the effective dimension of , the companion Stieltjes transform of , and particularly the effective ridge of . The SCT can actually be viewed as a direct translation to the KRR risk setting of .
3 Outline
In Section 2, we first introduce the Kernel Ridge Regression (KRR) predictor in functional space (Section 2.1) and formulate its train error and risk for random observations (Section 2.2).
The rest of the paper is then devoted to obtaining approximations for the KRR risk. In Section 3,the Signal Capture Threshold (SCT) is introduced and used to study the mean and variance of the KRR predictor (Sections 3.1 and 3.2). An approximation of the SCT in terms of the observed data is then given (Section 3.4). In Section 4, the expected risk and the expected empirical risk are approximated in terms of the SCT and its derivative w.r.t. the ridge . The SCT approximation of Section 3.4, together with the estimates of Section 4.1, leads to an approximation of the KRR risk by the Kernel Alignment Risk Estimator (KARE).
Setup
The regression problem is now stated as follows: given noisy observations with i.i.d. centered noises of unit variance, how can one reconstruct ?
We call the matrix the Gram matrix: in the classical setting, when the observations are (with ), is the usual Gram matrix, i.e. .
2 Training Error and Risk
We consider the least-squares error (MSE loss) of the KRR predictor, taking into account randomness of: (1) the test point, random observation to which is added a noise (2) the training data, made of observations plus noises , where and are i.i.d. The expected risk of the KRR predictor is thus taken w.r.t. the test and training observations and their noises. Unless otherwise specified, the expectations are taken w.r.t. all these sources of randomness.
For (fixed) observations , the empirical risk or training error of the KRR predictor is
For a random observation sampled from and a noise (where is centered of unit variance as before), the risk of the KRR predictor is defined by
From now on, we will assume that is a scalar product; note that in the classical setting, when is the evaluation of at a point with , the -norm is given by .
The following three operators are central to our analysis:
The KRR reconstruction operator , the KRR Integral Operator , and its empirical version are defined by
Note that in the noiseless regime (i.e. when ), we have . Also note that and are random operators, as they depend on the random observations. The operator is the natural generalization to our framework of the integration operator , which is defined with random observations with in the classical setting.
The reconstruction and empirical integral operators are linked by , which follows from the identity . As , we have that , and it follows that
3 Eigendecomposition of the Kernel
4 Gaussianity Assumption
As far as one is concerned with the first two moments of the operator, for large but finite , one can assume that the observations are Gaussian, i.e. that for any tuple of functions , the vector is a Gaussian vector.
Though our proofs use this assumption, the ideas in suggest a path to extend them beyond the Gaussian case, where our numerical experiments (see Figure 1) suggest that our results remain true.
Predictor Moments and Signal Capture Threshold
A central tool in our analysis of the KRR predictor is the Signal Capture Threshold (SCT):
For , the Signal Capture Threshold is the unique positive solution (see Section B.2 in the Appendix) to the equation:
In this section, we use and the derivative for the estimation of the mean and variance of the KRR predictor upon which the Kernel Alignment Risk Estimator of Section 4 is based.
The expected KRR predictor can be expressed in terms of the expected reconstruction operator
for a polynomial with nonnegative coefficients and .
More generally, if we decompose a true function along the principal components (i.e. eigenfunctions) of , the signal along the -th principal component is captured whenever the corresponding eigenvalue and lost when .
2 Variance of the predictor
We now estimate the variance of along each principal component in terms of the SCT and its derivative . Along the eigenfunction , the variance is estimated by , where
There is a constant and a polynomial with nonnegative coefficients and with such that
As shown in Section 4.1, understanding the variance along the principal components (rather than the covariances between the principal components) is enough to describe the risk.
3 Behavior of the SCT
The behavior of the SCT can be controlled by the following (agnostic of the exact spectrum of )
moreover is decreasing as a function of .
As , the above upper bound for becomes useless. Still, assuming that the spectrum of has a sufficiently fast power-law decay, we get:
If for some , there exist such that for any
4 Approximation of the SCT from the training data
Likewise, we have , as shown in the Appendix.
Risk Prediction with KARE
The Kernel Alignment Risk Estimator (KARE) is defined by
In the following, using Theorems 1 and 22, we give an approximation for the expected risk and expected empirical risk in terms of the SCT and the true function . This yields the important relation (2) in Section 4.2, which shows that the KARE can be used to efficiently approximate the kernel risk.
The expected risk is approximated, in terms of the SCT and the true function , by
There exists a constant and a polynomial with nonnegative coefficients and with , such that we have
(Sketch; the full proof is given in the Appendix). From the bias-variance decomposition:
In a Bayesian setting, assuming that is random with zero mean and covariance kernel , the optimal choices for the KRR predictor are and (see Section B.7 in the Appendix). When and , the formula of Theorem 6 simplifies (see Corollary in the Appendix) to
The empirical risk (or train error) can be analyzed with the same theoretical tools. Its approximation in terms of the SCT is given as follows:
There exists a constant and a polynomial with nonnegative coefficients and with such that we have
2 KARE: Kernel Alignment Risk Estimator
While the above approximations (Theorems 6 and 7) for the expected risk and empirical risk depend on , their combination yields the following relation, which is surprisingly independent of :
Since can be approximated from the training set (see Proposition 5), so can the expected risk. Assuming that the risk and empirical risk concentrate around their expectations, we get the KARE:
Note that both and are invariant (as is the risk) under the simultaneous rescaling .
The KARE can be used to optimize the risk over the space of kernels, for instance to choose the ridge and length-scale. The most popular kernel selection techniques are (see Figure 3):
Cross-validation: accurate estimator of the risk on a test set, but costly to optimize (the predictor must be recomputed for each kernel and differentiating it in the space of kernels is hard).
Kernel likelihood (Chapter 5 of ): efficient to optimize and takes into account the ridge, but not a risk estimator; unlike the risk, not invariant under the simultaneous rescaling .
Classical kernel alignment : very efficient to optimize and scale invariant, but not a risk estimator, not sensitive to small eigenvalues and inadequate to select hyperparameters such as the ridge.
The KARE combines the best features of the three above techniques:
it can be computed efficiently on the training data, and optimized over the space of kernels;
like the risk, it is invariant under the simultaneous rescaling ;
it is sensitive to the small Gram matrix eigenvalues and to the ridge .
Conclusion
In this paper, we introduce new techniques to study the Kernel Ridge Regression (KRR) predictor and its risk. We obtain new precise estimates for the test and train error in terms of a new object, the Signal Capture Threshold (SCT), which identifies the components of a true function that are being learned by the KRR: our estimates reveal a remarkable relation, which leads one to the Kernel Alignment Risk Estimator (KARE). The KARE is a new efficient way to estimate the risk of a kernel predictor based on the training data only. Numerically, we observe that the KARE gives a very accurate prediction of the risk for Higgs and MNIST datasets for a variety of classical kernels.
Broader Impact
This work is fundamental and may be used in any research area using Kernel methods, possibly leading to indirect social impacts. However, we do not predict any direct social impact.
Acknowledgements
The authors wish to thank A. Montanari and M. Wyart for useful discussions. This work is partly supported by the ERC SG CONSTAMIS. C. Hongler acknowledges support from the Blavatnik Family Foundation, the Latsis Foundation, and the the NCCR Swissmap.
References
Appendix
In Section A, we present the details for the numerical results presented in the main text (and in the Appendix) and we present additional experiments and some discussions.
In Section B, we present the proofs of the mathematical results presented in the main text.
Appendix A Numerical Results
For the MNIST dataset. We sample images of digits and from the MNIST training dataset (image size , edge pixels cropped, all pixels rescaled down to $+1-1\lambdakk=10Nk=5N=2000N_{2}=1000$ random samples of the MNIST training data.
For the Higgs Dataset. We randomly choose samples among those that do not have any missing features marked with from the Higgs training dataset. The samples have features, and we normalize each feature column down to $+1-1\lambdakkN=1000k=10Nk=5N=1000N_{2}=1000$ random samples of the Higgs training data.
A.2 KARE predicts risk for various Kernels
A.3 KRR predictor in function space
A.4 KARE predicts risk in average for small NN
A.5 SCT and its behavior
for . In particular, we have . In general, is the number of ways to partition into non-negative integers.
The true SCT is therefore approximated solving the following equation numerically
Note that in the Figure 2 in the main text, we limit the approximation to for because the multiplicity grows polynomially with .
Appendix B Proofs
Throughout our proofs, we will frequently rely on a polynomial analogue of the big-O notation, which we call big-P:
For two functions and (of one or several variables, defined on an arbitrary common domain ), we write if is nonnegative over and there exists a polynomial with nonnegative coefficients and such that over .
Note that the big-O notation corresponds to the case when the polynomial is of degree at most one.
B.1 Objects of Interest and general strategy
The central object of our analysis is the Gram matrix , in particular the related Stieltjes transform:
From now on, we denote by . Note that here, in the Appendix, we use the resolvent notation: in particular the KRR reconstruction operator is equal to .
Using the spectral decomposition of , the entries of are given by:
where the sum converges absolutely (thanks to the trace assumption on ) and the entries of are then given by:
where .
B.1.2 Shermann-Morrison Formula
As a result of Equations (8) and (9), the diagonal entries of the operator are equal to
Another important observation is that the Stieltjes transform and the are closely related.
Dividing both sides by and using Equation (10), we obtain
B.2 Concentration of the Stieltjes Transform
where the well-posedness of the two infinite sums of the r.h.s is granted by the fact that:
being the difference of two absolutely convergent series, the second sum is also absolutely convergent.
Regarding the concentration of the ’s around , we have the following result:
where only depends on .
since the derivative of is equal to . As a result, we obtain . Using the fact that since ,
Let and let us denote by the element of . Using Wick’s formula (Lemma 26), we have
where we recall that is the set of permutations with no fixed points and the product over is taken according to the order given by the cycle and does not depend on the starting point. Using the fact that the eigenvalues of are of the form with ,
Note that, since it has no fixed point, hence and thus is finite. This yields the inequality
where . ∎
where is the same constant as in Lemma 9.
The second bound is a direct consequence of the first one, Lemma 9 and convexity. It remains to prove the first bound. Recall Equation (13)
and hence, using a generalization of Cauchy-Schwarz inequality (Lemma 28), by:
where is the constant in Lemma 9.
First bound: Following similar ideas to the one which provided Equation (13), notice that
B.3 Properties of the effective dimension and SCT
We begin with general properties on the Signal Capture Threshold (which depends on and on the eigenvalues of ), valid for any kernel .
moreover is decreasing as a function of and is decreasing as a function of .
Recall that is the unique positive real number such that
Differentiating Equation (7), the derivative is given by:
Using the fact that , one has
Inverting this inequality yields the desired inequalities.
In order to study the variation of as a function of , we take the derivatives of Equation (7) w.r.t and , and notice that
In particular, since and , we get that hence is decreasing as a function of .
Finally, we conclude by noting that since , is an increasing function of and thus, from the Equation (15) we have that is decreasing as a function of and thus as a function of .
B.3.2 Bounds under polynomial decay hypothesis
For any , the SCT is the unique solution of In particular, is the unique solution of .
Since is decreasing from to , in order to study the asymptotic behavior of as goes to infinity, one has to understand the rate of explosion of as goes to zero.
If with , then when .
If with , then .
With no assumption on the spectrum of , the upper bound for the derivative of the SCT obtained in Proposition 3, becomes useless in the ridgeless limit . Yet, with the assumption of power-law decay of the eigenvalues of we can refine the bound with a meaningful one. In order to obtain this we first prove a technical lemma.
If with , then .
The derivative of the SCT with respect to at is given by:
Set , then for all , we have that . Thus,
Now, using Lemma 14, we are going to find a value of such that for some universal constant : this will conclude the proof.
,
We start by proving the inequalities for the derivative of the SCT . The left side of the inequality has already been proven in Proposition 3. For the right side, from Proposition 3, the derivative is decreasing in . In particular, by Lemma 15, Thus, the right side holds with .
B.4 The Operator A(z)A(z)
We have now the tools to describe the moments of the operator which allow us to describe the moments of the predictor .
using the big-P notation of Definition 5.
Note that in particular since the polynomial implicitly embedded in vanishes at , the right hand side tends to as .
Off-Diagonal terms: By a symmetry argument, we show that the off-diagonal terms are null. Consider the map defined by , and note that if and . The map is a symmetry for the observations, i.e. for any observations , and any functions , the vector and have the same law. Thus, the sampling operator and the operator have the same law, hence so do and , where
Diagonal terms: Using Equation 10, we have
From this, using the fact that , we obtain
Using Proposition 11, we can bound the first fraction by
Finally, putting everything together, we get:
B.4.2 Variance
thus, recalling that , we have
Thus, we obtain the following formula for the off-diagonal entry:
where only depend on .
where is as in Proposition 11.
We use Proposition 11 and Lemma 30 twice to obtain
Using Formula (10) for the diagonal entries of , we have:
Using Proposition 10, the absolute value of the r.h.s. can now be bounded by
Using the same notation as in the proof of Proposition 20,
We can bound the terms in the r.h.s. of the above by applying Proposition 10 and Lemma 18:
Let and ; then putting the pieces together we have
And finally, putting all the pieces together, we have
We can now describe the variance of the predictor. The variance of the predictor along the eigenfunction is estimated by , where
There is a constant such that, with the notation of Definition 5, we have
Using the law of total variance, we decompose the variance with respect to the observations and the vector of noise
Since the randomness is now only on through , from now on, we will lighten the notation by sometimes omitting the dependence in the expectations.
We first show how the approximation appears, and then establish the bounds which allow one to study the quality of this approximation.
Approximations: Decomposing the true function along the principal components with , we have
Combining Equations 20 and 21, we obtain the approximation
Second term: To approximate, we apply Cauchy’s inequality to Equation (17) of Theorem 17:
By using the fact that (see Proposition 3), we have that
Finally, by putting the bounds for the two terms together we have
B.5 Expected Risk
Similarly to the proof of Theorem 22, we explain how the approximation of the expected arises, then we establish the bounds which allow one to study the quality of this approximation.
Thus the variance term is approximately equal to:
Noting that from Equation 15, we have we get:
Hence, we get the following approximation of the variance term:
Putting the approximations of the bias and variance terms together, we obtain:
Now, we explain how to quantify the quality of the approximations, and thus how to get the bound stated in the theorem. Recall that, using the bias-variance decomposition, we split the expected risk into two terms, the bias term and the variance term. We show now that:
Combining the two inequations, and using the fact that , we then get the desired inequality.
We decompose the true function into for , and obtain
By the triangular inequality, we get that
Variance term: For the second term, recall that and that
Using Theorem 22, we can control the terms in the first series: there is a constant such that
whereas for the second series, as explained already above, we have
Finally, putting the pieces together, we conclude. ∎
B.6 Expected Empirical Risk
The expected empirical risk can be approximated as follows:
A small computation allows one to show that:
Using the definition of and the fact that the noise on the labels is centered and independent from the observations, this yields:
Similarly to the proof of Theorem 22, we explain how the approximation of the expected empirical risk appears, then we establish the bounds which allow one to study the quality of this approximation.
The second term can be approximated using Proposition 11 and Lemma 27: this yields
Hence, putting the two approximations together, the expected empirical risk is approximated by:
Now, we explain how to quantify the quality of the approximations, and thus how to get the bound stated in the theorem. Recall that, we split the expected empirical risk into two terms.
First term: We have already seen in Theorem 22 that by applying Lemma 27 to Equation (17) of Theorem 17 we get
Second Term: Using Proposition 11 and Lemma 27:
B.7 Bayesian Setting
Differentiating w.r.t. , we obtain that the above error is minimized when
In other terms, in this Bayesian setting, the KRR predictor with kernel and ridge minimizes the expected squared error at all points .
Using Theorem 6, we obtain the following approximation of the expected risk for a general kernel and ridge :
For a random true function of zero mean and covariance kernel the expected risk is approximated by
This formula can be further simplified. First note that differentiating both sides of Equation 7 w.r.t. to , we obtain that
Secondly, differentiating both sides of Equation 7, we obtain, writing
Putting everything together, we obtain that
B.8 Technical Lemmas
For any family of square matrices of same size, any permutation , we define:
where the product inside the trace is taken following the order given by the cycle and, by the cyclic property, does not depend on the starting point (see ). For example if and is the product of transpositions
If is a family of square symmetric random matrices of size independent from a standard Gaussian vector of size , we have
Furthermore, if and are independent Gaussian vectors of size and independent from , then
therefore, it is sufficient to prove that
B.8.2 Bound on derivatives
Given a bound on a holomorphic function, one can obtain a bound on its derivative.
The inequality follows by considering and using the fact that is decreasing. ∎
B.8.3 Generalized Cauchy-Schwarz inequality
Another result that we will use is the following generalization of the Cauchy-Schwarz inequality, which is a consequence of Hölder’s inequality.
For complex random variables , we have
The proof is done using an induction argument. The initialization, i.e. when , is trivial.
For the induction step, assume that the result is true for terms and let us prove it for terms. By Hölder’s inequality applied for and , we obtain:
where the second inequality is obtained by the induction hypothesis. ∎