Regression Conformal Prediction with Nearest Neighbours

In this paper we apply Conformal Prediction (CP) to the k-Nearest Neighbours Regression (k-NNR) algorithm and propose ways of extending the typical nonconformity measure used for regression so far. Unlike traditional regression methods which produce point predictions, Conformal Predictors output predictive regions that satisfy a given confidence level. The regions produced by any Conformal Predictor are automatically valid, however their tightness and therefore usefulness depends on the nonconformity measure used by each CP. In effect a nonconformity measure evaluates how strange a given example is compared to a set of other examples based on some traditional machine learning algorithm. We define six novel nonconformity measures based on the k-Nearest Neighbours Regression algorithm and develop the corresponding CPs following both the original (transductive) and the inductive CP approaches. A comparison of the predictive regions produced by our measures with those of the typical regression measure suggests that a major improvement in terms of predictive region tightness is achieved by the new measures.


Introduction
A drawback of traditional machine learning algorithms is that they do not associate their predictions with confidence information, instead they only output simple predictions.However, some kind of confidence information about predictions is of paramount importance in many risk-sensitive applications such as those used for medical diagnosis (Holst, Ohlsson, Peterson, & Edenbrandt, 1998).
Of course some machine learning theories that produce confidence information do exist.One can apply the theory of Probably Approximately Correct learning (PAC theory, Valiant, 1984) to an algorithm in order to obtain upper bounds on the probability of its error with respect to some confidence level.The bounds produced by PAC theory though, will be very weak unless the data set to which the algorithm is being applied is particularly clean, which is rarely the case.Nouretdinov, Vovk, Vyugin, and Gammerman (2001b) demonstrated the crudeness of PAC bounds by applying one of the best bounds, by Littlestone and Warmuth (Cristianini & Shawe-Taylor, 2000, Thm. 4.25, 6.8), to the USPS data set.
Another way of obtaining confidence information is by using the Bayesian framework for producing algorithms that complement individual predictions with probabilistic measures of their quality.In order to apply the Bayesian framework however, one is required to have some prior knowledge about the distribution generating the data.When the correct prior is known, Bayesian methods provide optimal decisions.For real world data sets though, as the required knowledge is not available, one has to assume the existence of an arbitrarily chosen prior.In this case, since the assumed prior may be incorrect, the resulting confidence levels may also be "incorrect"; for example the predictive regions output for the 95% confidence level may contain the true label in much less than 95% of the cases.This signifies a major failure as we would expect confidence levels to bound the percentage of expected errors.An experimental demonstration of this negative aspect of Bayesian methods in the case of regression is given in Section 8, while a detailed experimental examination for both classification and regression was performed by Melluish, Saunders, Nouretdinov, and Vovk (2001).
A different approach to confidence prediction was suggested by Gammerman, Vapnik, and Vovk (1998) (and later greatly improved by Saunders, Gammerman, & Vovk, 1999), who proposed what we call in this paper "Conformal Prediction" (CP).A thorough analysis of CP was given by Vovk, Gammerman, and Shafer (2005), while an overview was presented by Gammerman and Vovk (2007).Conformal Predictors are built on top of traditional machine learning algorithms and accompany each of their predictions with valid measures of confidence.Unlike Bayesian methods, CPs do not require any further assumptions about the distribution of the data, other than that the data are independently and identically distributed (i.i.d.); although this is still a strong assumption, it is almost universally accepted in machine learning.Even if the traditional algorithm on which a CP is based makes some extra assumptions that are not true for a particular data set, the validity of the predictive regions produced by the CP will not be affected.The resulting predictive regions might be uninteresting, but they will still be valid, as opposed to the misleading regions produced by Bayesian methods.Furthermore, in contrast to PAC methods, the confidence measures they produce are useful in practice.Different variants of CPs have been developed based on Support Vector Machines (Saunders et al., 1999;Saunders, Gammerman, & Vovk, 2000), Ridge Regression (Nouretdinov, Melluish, & Vovk, 2001a;Papadopoulos, Proedrou, Vovk, & Gammerman, 2002a), k-Nearest Neighbours for classification (Proedrou, Nouretdinov, Vovk, & Gammerman, 2002;Papadopoulos, Vovk, & Gammerman, 2002b) and Neural Networks (Papadopoulos, Vovk, & Gammerman, 2007), all of which have been shown to give reliable and high quality confidence measures.Moreover, CP has been applied successfully to many problems such as the early detection of ovarian cancer (Gammerman et al., 2009), the classification of leukaemia subtypes (Bellotti, Luo, Gammerman, Delft, & Saha, 2005), the diagnosis of acute abdominal pain (Papadopoulos, Gammerman, & Vovk, 2009a), the prediction of plant promoters (Shahmuradov, Solovyev, & Gammerman, 2005), the recognition of hypoxia electroencephalograms (EEGs) (Zhang, Li, Hu, Li, & Luo, 2008), the prediction of network traffic demand (Dashevskiy & Luo, 2008) and the estimation of effort for software projects (Papadopoulos, Papatheocharous, & Andreou, 2009b).
The only drawback of the original CP approach is its relative computational inefficiency.This is due to the transductive nature of the approach, which entails that all computations have to start from scratch for every test example.This renders it unsuitable for application to large data sets.For this reason a modification of the original CP approach, called Inductive Conformal Prediction (ICP), was proposed by Papadopoulos et al. (2002a) for regression and by Papadopoulos et al. (2002b) for classification.As suggested by its name, ICP replaces the transductive inference followed in the original approach with inductive inference.Consequently, ICPs are almost as computationally efficient as their underlying algorithms.This is achieved at the cost of some loss in the quality of the produced confidence measures, but this loss is negligible, especially when the data set in question is large, whereas the improvement in computational efficiency is significant.A computational complexity comparison between the original CP and ICP approaches was performed by Papadopoulos (2008).From now on, in order to differentiate clearly between the original CP and ICP approaches the former will be called Transductive Conformal Prediction (TCP).
In order to apply CP (either TCP or ICP) to a traditional algorithm one has to develop a nonconformity measure based on that algorithm.This measure evaluates the difference of a new example from a set (actually a multiset or bag) of old examples.Nonconformity measures are constructed using as basis the traditional algorithm to which CP is being applied, called the underlying algorithm of the resulting Conformal Predictor.In effect nonconformity measures assess the degree to which the new example disagrees with the attribute-label relationship of the old examples, according to the underlying algorithm of the CP.It is worth to note that many different nonconformity measures can be constructed for each traditional algorithm and each of those measures defines a different CP.This difference, as we will show in the next section, does not affect the validity of the results produced by the CPs, it only affects their efficiency.
In this paper we are only interested in the problem of regression and we focus on k -Nearest Neighbours Regression (k-NNR) as underlying algorithm, which is one of the most popular machine learning techniques.The first regression CPs were proposed by Nouretdinov et al. (2001a) following the TCP approach and by Papadopoulos et al. (2002a) following the ICP approach, both based on the Ridge Regression algorithm.As opposed to the conventional point predictions, the output of regression CPs is a predictive region that satisfies a given confidence level.
The typical nonconformity measure used so far in the case of regression is the absolute difference |y i − ŷi |, between the actual label y i of the example i and the predicted label ŷi of the underlying algorithm for that example, given the old examples as training set.Here we propose six extensions to this nonconformity measure for k -Nearest Neighbours Regression and develop the corresponding Inductive and Transductive CPs; unfortunately although all six new measures can be used with the ICP approach, only two of them can be used with TCP.Our definitions normalize the standard measure based on the expected accuracy of the underlying algorithm for each example, which makes the width of the resulting predictive regions vary accordingly.As a result, the predictive regions produced by our measures are in general much tighter than those produced by the standard regression measure.This paper extends our previous work (Papadopoulos, Gammerman, & Vovk, 2008) where the k -Nearest Neighbours Regression TCP was developed using two normalized nonconformity measures.It is also worth mentioning that one other such nonconformity measure definition was presented by Papadopoulos et al. (2002a) for the Ridge Regression ICP.
The rest of this paper is structured as follows.In the next section we discuss the general idea on which CPs are based.Then in Sections 3 and 4 we describe the k -Nearest Neigh-bours Regression TCP and ICP respectively using the typical regression nonconformity measure.In Section 5 we give our new nonconformity measure definitions and explain the rationale behind them.Section 6 analyses further one of our new nonconformity measures and demonstrates that under specific assumptions it gives asymptotically optimal predictive regions.Section 7 details our experimental results with the 3 TCPs and 7 ICPs developed based on the different measures, while Section 8 compares our methods with Gaussian Process Regression (Rasmussen & Williams, 2006), which is one of the most popular Bayesian approaches.Finally, Section 9 gives our conclusions and discusses some possible future directions of this work.

Conformal Prediction
In this section we briefly describe the idea behind Conformal Prediction; for a more detailed description the interested reader is referred to the book by Vovk et al. (2005).We are given a training set {z 1 , . . ., z l } of examples, where each z i ∈ Z is a pair (x i , y i ); x i ∈ R d is the vector of attributes for example i and y i ∈ R is the label of that example.We are also given a new unlabeled example x l+1 and our task is to state something about our confidence in different values ỹ for the label y l+1 of this example.As mentioned in Section 1 our only assumption is that all (x i , y i ), i = 1, 2, . . ., are generated independently from the same probability distribution.
First let us define the concept of a nonconformity measure.Formally, a nonconformity measure is a family of functions A n : Z (n−1) × Z → R, n = 1, 2, . . .(where Z (n−1) is the set of all multisets of size n − 1), which assign a numerical score to each example z i , indicating how different it is from the examples in the multiset {z 1 , . . ., z i−1 , z i+1 , . . ., z n }.
As mentioned in Section 1 each nonconformity measure is based on some traditional machine learning method, which is called the underlying algorithm of the corresponding CP.
and y i .Now suppose we are interested in some particular guess ỹ for the label of x l+1 .Adding this new example (x l+1 , ỹ) to our known data set {(x 1 , y 1 ), . . ., (x l , y l )} gives the extended set {z 1 , . . ., z l+1 } = {(x 1 , y 1 ), . . ., (x l+1 , ỹ)}; (4) notice that the only unknown component of this set is the label ỹ.We can now use a nonconformity measure A l+1 to compute the nonconformity score of each example z i , i = 1, . . ., l + 1 in (4).The nonconformity score α l+1 on its own does not really give us any information, it is just a numeric value.However, we can find out how unusual z l+1 is according to A l+1 by comparing α l+1 with all other nonconformity scores.This comparison can be performed with the function (we leave the dependence of the left-hand side on z 1 , . . ., z l , x l+1 implicit, but it should be always kept in mind).We call the output of this function, which lies between 1 l+1 and 1, the p-value of ỹ, as that is the only part of (4) we were not given.An important property of ( 5) is that ∀δ ∈ [0, 1] and for all probability distributions P on Z, P {{z 1 , . . ., z l+1 } : p(y l+1 ) ≤ δ} ≤ δ; (6) a proof was given by Nouretdinov et al. (2001b).As a result, if the p-value of a given label is below some very low threshold, say 0.05, this would mean that this label is highly unlikely as such sets will only be generated at most 5% of the time by any i.i.d.process.Assuming we could calculate the p-value of every possible label ỹ, as described above, we would be able to exclude all labels that have a p-value under some very low threshold (or significance level ) δ and have at most δ chance of being wrong.Consequently, given a confidence level 1 − δ a regression conformal predictor outputs the set i.e. the set of all labels that have a p-value greater than δ.Of course it would be impossible to explicitly calculate the p-value of every possible label ỹ ∈ R. In the next section we describe how one can compute the predictive region (7) efficiently for k -Nearest Neighbours Regression.
It should be noted that the p-values computed by any CP will always be valid in the sense of satisfying (6) regardless of the particular algorithm or nonconformity measure definition it uses.The choice of algorithm, nonconformity measure definition and any parameters only affects the tightness of the predictive regions output by the CP, and consequently their usefulness.To demonstrate the influence of an inadequate nonconformity measure definition on the results of a CP, let us consider the case of a trivial definition that always returns the same value α i for any given example (x i , y i ).This will make all p-values equal to 1 and will result in the predictive region R regardless of the required confidence level.Although this region is useless since it does not provide us with any information, it is still valid as it will always contain the true label of the example.Therefore even in the worst case of using some totally wrong nonconformity measure definition or algorithm, the regions produced by the corresponding CP will be useless, but they will never be misleading.

k -Nearest Neighbours Regression TCP
The k -Nearest Neighbours algorithms base their predictions on the k training examples that are nearest to the unlabeled example in question according to some distance measure, such as the Euclidean distance.More specifically, for an input vector x l+1 the k -Nearest Neighbours Regression (k -NNR) algorithm finds the k nearest training examples to x l+1 and outputs the average (in some cases the median is also used) of their labels as its prediction.A refined form of the method assigns a weight to each one of the k examples depending on their distance from x l+1 , these weights determine the contribution of each label to the calculation of its prediction; in other words it predicts the weighted average of their labels.It is also worth to mention that the performance of the Nearest Neighbours method can be enhanced by the use of a suitable distance measure or kernel for a specific data set.
Here we will consider the version of the k -NNR method which predicts the weighted average of the k nearest examples.In our experiments we used the Euclidean distance, which is the most commonly used distance measure.It will be easy to see that the use of a kernel function or of a different distance measure will not require any changes to our method.
As mentioned in Section 1 in order to create any CP we need to define a nonconformity measure based on the underlying algorithm in question.First let us consider the nonconformity measure where ŷi is the prediction of k -NNR for x i based on the examples {(x 1 , y 1 ), . . ., (x i−1 , y i−1 ), (x i+1 , y i+1 ), . . ., (x l+1 , ỹ)}; recall from Section 2 that ỹ is the assumed label for the new example x l+1 .Following Nouretdinov et al. (2001a) and Vovk et al. (2005) we express the nonconformity score α i of each example i = 1, . . ., l + 1 as a piecewise-linear function of ỹ To do this we define a i and b i as follows: • a l+1 is minus the weighted average of the labels of the k nearest neighbours of x l+1 and b l+1 = 1; . ., x l } multiplied by their corresponding weights, and b i is minus the weight of x l+1 ; • if i ≤ l and x l+1 is not one of the k nearest neighbours of x i , a i is y i minus the weighted average of the labels of the k nearest neighbours of x i , and b i = 0.
As a result the p-value p(ỹ) (defined by ( 5)) corresponding to ỹ can only change at the points where α i (ỹ) − α l+1 (ỹ) changes sign for some i = 1, . . ., l.This means that instead of having to calculate the p-value of every possible ỹ, we can calculate the set of points ỹ on the real line that have a p-value p(ỹ) greater than the given significance level δ, leading to a feasible prediction algorithm.
Algorithm 1: k-NNR TCP Input: training set {(x 1 , y 1 ), . . ., (x l , y l )}, new example x l+1 , number of nearest neighbours k and significance level δ.P := {}; for i = 1 to l + 1 do Calculate a i and b i for example and a i = a l+1 then add (11) to P ; end Sort P in ascending order obtaining y (1) , . . ., y (u) ; Add y (0) := −∞ and y (u+1) := ∞ to P ; N (j) := 0, j = 0, . . ., u; M (j) := 0, j = 1, . . ., u; For each i = 1, . . ., l + 1, let Each set S i (always closed) will either be an interval, a ray, the union of two rays, the real line, or empty; it can also be a point, which is a special case of an interval.As we are interested in |a i + b i ỹ| we can assume that b i ≥ 0 for i = 1, . . ., l + 1 (if not we multiply both a i and b i by −1).If b i = b l+1 , then α i (ỹ) and α l+1 (ỹ) are equal at two points (which may coincide): in this case S i is an interval (maybe a point) or the union of two rays.If b i = b l+1 = 0, then α i (ỹ) = α l+1 (ỹ) at just one point: and S i is a ray, unless a i = a l+1 in which case S i is the real line.If b i = b l+1 = 0, then S i is either empty or the real line.
To calculate the p-value p(ỹ) for any potential label ỹ of the new example x l+1 , we count how many S i include ỹ and divide by l + 1, As ỹ increases p(ỹ) can only change at the points ( 10) and ( 11), so for any significance level δ we can find the set of ỹ for which p(ỹ) > δ as the union of finitely many intervals and rays.Algorithm 1 implements a slightly modified version of this idea.It creates a list of the points ( 10) and ( 11), sorts it in ascending order obtaining y (1) , . . ., y (u) , adds y (0) = −∞ to the beginning and y (u+1) = ∞ to the end of this list, and then computes N (j), the number of S i which contain the interval (y (j) , y (j+1) ), for j = 0, . . ., u, and M (j) the number of S i which contain the point y (j) , for j = 1, . . ., u.

k -Nearest Neighbours Regression ICP
As the TCP technique follows a transductive approach, most of its computations are repeated for every test example.The reason for this is that the test example is included in the training set of the underlying algorithm of the TCP in order to calculate the required nonconformity measures.This means that the underlying algorithm is retrained for every test example, which renders TCP quite computationally inefficient for application to large data sets.Inductive Conformal Predictors (ICP) are based on the same general idea described in Section 2, but follow an inductive approach, which allows them to train their underlying algorithm just once.This is achieved by splitting the training set (of size l) into two smaller sets, the calibration set with q < l examples and the proper training set with m := l − q examples.The proper training set is used for creating the prediction rule D {z 1 ,...,zm} and only Algorithm 2: k-NNR ICP Input: training set {(x 1 , y 1 ), . . ., (x l , y l )}, test set {x l+1 , . . ., x l+r }, number of nearest neighbours k, number of calibration examples q, and significance level δ. m := l − q; P := {}; for i = 1 to q do Calculate ŷm+i using {(x 1 , y 1 ), . . ., (x m , y m )} as training set; Calculate α m+i for the pair z m+i = (x m+i , y m+i ); Add α m+i to P ; end Sort P in descending order obtaining α (m+1) , . . ., α (m+q) ; s := δ(q + 1) ; for g = 1 to r do Calculate ŷl+g using {(x 1 , y 1 ), . . ., (x m , y m )} as training set; Output: the predictive region (ŷ l+g − α (m+s) , ŷl+g + α (m+s) ).end the examples in the calibration set are used for calculating the p-value of each possible label of the new test example.More specifically, the non-conformity score α m+i of each example z m+i in the calibration set {z m+1 , . . ., z m+q } is calculated as the degree of disagreement between the prediction ŷm+i = D {z 1 ,...,zm} (x m+i ) (13) and the true label y m+i .In the same way, the non-conformity score α l+g (ỹ) for the assumed label ỹ of the new test example x l+g is calculated as the degree of disagreement between ŷl+g = D {z 1 ,...,zm} (x l+g ) (14) and ỹ.Notice that the nonconformity scores of the examples in the calibration set only need to be computed once.Using these non-conformity scores the p-value of each possible label ỹ of x l+g can be calculated as As with the original CP approach it is impossible to explicitly consider every possible label ỹ ∈ R of a new example x l+g and calculate its p-value.However, now both the nonconformity scores of the calibration set examples α m+1 , . . ., α m+q and the k-NNR prediction ŷl+g remain fixed for each test example x l+g , and the only thing that changes for different values of the assumed label ỹ is the nonconformity score α l+g .Therefore p(ỹ) changes only at the points where α l+g (ỹ) = α i for some i = m + 1, . . ., m + q.As a result, for a confidence level 1 − δ we only need to find the biggest α i such that when α l+g (ỹ) = α i then p(ỹ) > δ, which will give us the maximum and minimum ỹ that have a p-value bigger than δ and consequently the beginning and end of the corresponding predictive region.More specifically, we sort the nonconformity scores of the calibration examples in descending order obtaining the sequence α (m+1) , . . ., α (m+q) , and output the predictive region where The whole process is detailed in Algorithm 2. Notice that as opposed to Algorithm 1 where all computations have to be repeated for every test example, here only the part inside the second for loop is repeated.
The parameter q given as input to Algorithm 2 determines the number of training examples that will be allocated to the calibration set and the nonconformity scores of which will be used by the ICP to generate its predictive regions.These examples should only take up a small portion of the training set, so that their removal will not dramatically reduce the predictive ability of the underlying algorithm.As we are mainly interested in the confidence levels of 99% and 95%, the calibration sizes we use are of the form q = 100n − 1, where n is a positive integer (see ( 18)).

Normalized Nonconformity Measures
The main aim of this work was to improve the typical regression nonconformity measure (8) by normalizing it with the expected accuracy of the underlying method.The intuition behind this is that if two examples have the same nonconformity score as defined by ( 8) and the prediction ŷ for one of them was expected to be more accurate than the other, then the former is actually stranger than the latter.This leads to predictive regions that are larger for the examples which are more difficult to predict and smaller for the examples which are easier to predict.
The first measure of expected accuracy we use is based on the distance of the example from its k nearest neighbours.Since the k nearest training examples are the ones actually used to derive the prediction of our underlying method for an example, the nearer these are to the example, the more accurate we expect this prediction to be.
For each example z i , let us denote by T i the training set used for generating the prediction ŷi .This will be the set in the case of the TCP and the set in the case of the ICP.Furthermore, we denote the k nearest neighbours of x i in T i as and the sum of the distances between x i and its k nearest neighbours as We could use d k i as a measure of accuracy, in fact it was used successfully in our previous work (Papadopoulos et al., 2008).However, here in order to make this measure more consistent across different data sets we use which compares the distance of the example from its k nearest neighbours with the median of the distances of all training examples from their k nearest neighbours.Using λ k i we defined the nonconformity measures: and where the parameter γ ≥ 0 controls the sensitivity of each measure to changes of λ k i ; in the first case increasing γ results in a less sensitive nonconformity measure, while in the second increasing γ results in a more sensitive measure.The exponential function in definition ( 25) was chosen because it has a minimum value of 1, since λ k i will always be positive, and grows quickly as λ k i increases.As a result, this measure is more sensitive to changes when λ k i is big, which indicates that an example is unusually far from the training examples.
The second measure of accuracy we use is based on how different the labels of the example's k nearest neighbours are, which is measured as their standard deviation.The more these labels agree with each other, the more accurate we expect the prediction of the k-nearest neighbours algorithm to be.For an example x i , we measure the standard deviation of the labels of its k neighbours as where Again to make this measure consistent across data sets we divide it with the median standard deviation of the k nearest neighbour labels of all training examples In the same fashion as ( 24) and ( 25) we defined the nonconformity measures: and where again the parameter γ controls the sensitivity of each measure to changes of ξ k i .Finally by combining λ k i and ξ k i we defined the nonconformity measures: and where in (31) the parameter γ controls the sensitivity of the measure to changes of both λ k i and ξ k i , whereas in (32) there are two parameters γ and ρ, which control the sensitivity to changes of λ k i and ξ k i respectively.In order to use these nonconformity measures with the k-Nearest Neighbours Regression TCP we need to calculate their nonconformity scores as α i = |a i +b i ỹ|.We can easily do this for ( 24) and ( 25) by computing a i and b i as defined in Section 3 and then dividing both by (γ + λ k i ) for nonconformity measure (24) and by exp(γλ k i ) for nonconformity measure (25).Unfortunately however, the same cannot be applied for all other nonconformity measures we defined since ξ k i depends on the labels of the k nearest examples, which change for the k nearest neighbours of x l+1 as we change ỹ.For this reason TCP is limited to using only nonconformity measures ( 24) and (25).

Theoretical Analysis of Nonconformity Measure (29)
In this section we examine k-NNR ICP with nonconformity measure (29) under some specific assumptions and show that, under these assumptions, the predictive regions produced are asymptotically optimal; it is important to note that these assumptions are not required for the validity of the resulting predictive regions.We chose not to formalize all the conditions needed for our conclusions, as this would have made our statement far too complicated.Assume that each label y i is generated by a normal distribution N (µ x i , σ 2 x i ), where µ x and σ x are smooth functions of x, that each x i is generated by a probability distribution that is concentrated on a compact set and whose density is always greater than some constant > 0, and that k 1, m k and q k.In this case nonconformity measure ( 29) with γ = 0 will be where the division of s k i by median({s k j : z j ∈ T i }) is ignored since the latter does not change within the same data set.The values will follow an approximately standard normal distribution, and for a new example x l+g with probability close to 1 − δ we have where α (m+1) , . . ., α (m+q) are the nonconformity scores α m+1 , . . ., α m+q sorted in descending order.As a result we obtain the region which, on one hand, is close to the standard (and optimal in various senses) prediction interval for the normal model and, on the other hand, is almost identical to the region (35) of k-NNR ICP (recall that we set γ = 0 and ξ k i = s k i ).

Experimental Results
Our methods were tested on six benchmark data sets from the UCI (Frank & Asuncion, 2010) and DELVE (Rasmussen et al., 1996) repositories: • Boston Housing, which lists the median house prices for 506 different areas of Boston MA in $1000s.Each area is described by 13 attributes such as pollution and crime rate.
• Abalone, which concerns the prediction of the age of abalone from physical measurements.The data set consists of 4177 examples described by 8 attributes such as diameter, height and shell weight.
• Computer Activity, which is a collection of a computer systems activity measures from a Sun SPARCstation 20/712 with 128 Mbytes of memory running in a multiuser university department.It consists of 8192 examples of 12 measured values, such as the number of system buffer reads per second and the number of system call writes per second, at random points in time.The task is to predict the portion of time that the cpus run in user mode, ranging from 0 to 100.We used the small variant of the data set which contains only 12 of the 21 attributes.
• Kin, which was generated from a realistic simulation of the forward dynamics of an 8 link all-revolute robot arm.The task is to predict the distance of the end-effector from a target.The data set consists of 8192 examples described by attributes like joint positions and twist angles.We used the 8nm variant of the data set which contains 8 of the 32 attributes, and is highly non-linear with moderate noise.
• Bank, which was generated from simplistic simulator of the queues in a series of banks.
The task is to predict the rate of rejections, i.e. the fraction of customers that are turned away from the bank because all the open tellers have full queues.The data set consists of 8192 examples described by 8 attributes like area population size and maximum possible length of queues.The 8nm variant of the data set was used with the same characteristics given in the description of the Kin data set.
• Pumadyn, which was generated from a realistic simulation of the dynamics of a Unimation Puma 560 robot arm.It consists of 8192 examples and the task is to predict the angular acceleration of one of the robot arm's links.Each example is described by 8 attributes, which include angular positions, velocities and torques of the robot arm.The 8nm variant of the data set was used with the same characteristics given in the description of the Kin data set.
Before conducting our experiments the attributes of all data sets were normalized to a minimum value of 0 and a maximum value of 1.Our experiments consisted of 10 random runs of a fold cross-validation process.Based on their sizes the Boston Housing and Abalone data sets were split into 10 and 4 folds respectively, while the other four were splint into 2 folds.For determining the number k of nearest neighbours that was used for each data set, one third of the training set of its first fold was held-out as a validation set and the base algorithm was tested on that set with different k, using the other two thirds for training.The number of neighbours k that gave the smallest mean absolute error was selected.Note that, as explained in Section 2, the choice of k and any other parameter does not affect the validity of the results produced by the corresponding CP, it only affects their efficiency.The calibration set sizes were set to q = 100n − 1 (see Section 4), where n was chosen so that q was approximately 1/10th of each data set's training size; in the case of the Boston Housing data set the smallest value n = 1 was used.Table 1 gives the number of folds, number of nearest neighbours k, and calibration set size q used in our experiments for each data set, together with the number of examples and attributes it consists of and the width of its range of labels.
The parameters γ and ρ of our nonconformity measures were set in all cases to 0.5, which seems to give very good results with all data sets and measures.It is worth to note however, that somewhat tighter predictive regions can be obtained by adjusting the corresponding parameter(s) of each measure for each data set.We chose to fix these parameters to 0.5 here, so as to show that the remarkable improvement in the predictive region widths resulting from the use of the new nonconformity measures does not depend on fine tuning these parameters.
Since our methods output predictive regions instead of point predictions, the main aim of our experiments was to check the tightness of these regions.The first two parts of Tables 2-7 report the median and interdecile mean widths of the regions produced for every data set by each nonconformity measure of the k-NNR TCP and ICP for the 99%, 95% and 90% confidence levels.We chose to report the median and interdecile mean values instead of the mean so as to avoid the strong impact of a few extremely large or extremely small regions.
In the third and last parts of Tables 2-7 we check the reliability of the obtained predictive regions for each data set.This is done by reporting the percentage of examples for which the true label is not inside the region output by the corresponding method.In effect this checks empirically the validity of the predictive regions.The percentages reported here are very close to the required significance levels and do not change by much for the different nonconformity measures.
Figures 1-6 complement the information detailed in Tables 2-7 by displaying boxplots which show the median, upper and lower quartiles, and upper and lower deciles of the predictive region widths produced for each data set.Each chart is divided into three parts, separating the three confidence levels we consider, and each part contains 10 boxplots of which the first three are for the k-NNR TCP with the nonconformity measures (8), ( 24) and ( 25), and the remaining seven are for the k-NNR ICP with all nonconformity measures.
A transformation of the width values reported in Tables 2-7 to the percentage of the range of possible labels they represent shows that in general the predictive regions produced by all our methods are relatively tight.The median width percentages of all nonconformity measures and all data sets are between 17% and 86% for the 99% confidence level and between 11% and 47% for the 95% confidence level.If we now consider the best performing nonconformity measure for each data set, the worst median width percentage for the 99% confidence level is 61% and for the 95% confidence level it is 43% (both for the pumadyn data set).
By comparing the predictive region tightness of the different nonconformity measures for each method both in Tables 2-7 and in Figures 1-6, one can see the relatively big improvement that our new nonconformity measures achieve as compared to the standard      Finally, in Table 8 we report the processing times of the two approaches.We use two rows for reporting the times of the ICP, one for measure (8) and one for all new measures, since the new measures require some extra computations; i.e. finding the distances of all training examples from their k nearest neighbours and/or the standard deviation of their k nearest neighbour labels.We also group the times of the Computer Activity, Kin, Bank and Pumadyn data sets, which were almost identical as they consist of the same number of examples, into one column.This table demonstrates the huge computational efficiency improvement of ICP over TCP.It also shows that there is some computational overhead involved in using the new nonconformity measures with ICP, but it is not so important, especially baring in mind the degree of improvement they bring in terms of predictive region tightness.

Comparison with Gaussian Process Regression
In this section we compare the predictive regions produced by our methods with those produced by Gaussian Processes (GPs, Rasmussen & Williams, 2006), which is one of the most popular Bayesian machine learning approaches.We first compare Gaussian Process Regression (GPR) and the k-NNR CPs on artificially generated data that satisfy the GP prior and then check the results of GPR on three of the data sets described in Section 7, namely Boston Housing, Abalone and Computer Activity.Our implementation of GPR was based on the Matlab code that accompanies the work of Rasmussen and Williams.
For our first set of experiments we generated 100 artificial data sets consisting of 1000 training and 1000 test examples with inputs drawn from a uniform distribution over [−10, 10] 5 .The labels of each data set were generated from a Gaussian Process with a covariance function defined as the sum of a squared exponential (SE) covariance and independent noise and hyperparameters (l, σ f , σ n ) = (1, 1, 0.1); i.e. a unit length scale, a unit signal magnitude and a noise standard deviation of 0.1.We then applied GPR on these data sets using exactly the same covariance function and hyperparameters and compared the results with those of the k-NNR CPs (which do not take into account any information about how the data were generated).Table 9 reports the results over all 100 data sets obtained by GPR and our methods in the same manner as Tables 2-7.In this case, since the data meets the GPR prior, the percentage of labels outside the predictive regions produced by GPR are more or less equal to the required significance level as we would expect.The same is true for the regions produced by all our methods.Also, although the predictive regions produced by GPR are tighter than those produced by our methods, the difference between the two is very small.
Our experiments on the three benchmark data sets were performed following exactly the same setting with our experiments on the two CPs, including the use of the same seed for each fold-cross validation run.In terms of data preprocessing, we normalised the attributes of each data set setting the mean of each attribute to 0 and its standard deviation to 1, while we also centred the labels of each data set so as to have a zero mean; these preprocessing steps are advisable for GPR.We tried out a SE covariance and a Matern covariance with smoothness set to v = 3/2 and v = 5/2.In the case of the SE covariance, we used the automatic relevance determination version of the function, which allows for a separate length-scale for each attribute determined by a corresponding hyperparameter.In all cases   the actual covariance function was defined as the sum of the corresponding covariance and independent noise.All hyperparameters were adapted by maximizing marginal likelihood on each training set as suggested by Rasmussen and Williams (2006); the adaptation of hyperparameters using leave-one-out cross-validation produces more or less the same results.Tables 10-12 report the results obtained by GRP on the three data sets with each covariance function.By comparing the values reported in the first two parts of this tables with those in Tables 2-4 one can see that the regions produced by GPR are tighter in almost all cases.However, the percentage of predictive regions that do not include the true label of the example is much higher than the required for the 95% and 99% confidence levels.This shows that the predictive regions produced by GPR are not valid and therefore they are misleading if the correct prior is not known.On the contrary, as demonstrated in Section 2, CPs produce valid predictive regions even if the parameters or underlying algorithm used are totally wrong.

Conclusions
We presented the Transductive and Inductive Conformal Predictors based on the k-Nearest Neighbours Regression algorithm.In addition to the typical regression nonconformity measure, we developed six novel definitions which take into account the expected accuracy of the k-NNR algorithm on the example in question.Our definitions assess the expected accuracy of k-NNR on the example based on its distances from its k nearest examples ( 24) and ( 25), on the standard deviation of their labels ( 29) and ( 30), or on a combination of the two (31) and (32).
The experimental results obtained by applying our methods to various data sets show that in all cases they produce reliable predictive intervals that are tight enough to be useful in practice.Additionally, they illustrate the great extent to which our new nonconformity measure definitions improve the performance of both the transductive and inductive method in terms of predictive region tightness.In the case of the ICP, with which all new measures were evaluated, definitions (31) and (32) appear to be superior to all other measures, giving the overall tightest predictive regions.Moreover, a comparison between the TCP and ICP methods suggests that, when dealing with relatively large data sets the use of nonconformity measures (31) and (32) makes ICP perform equally well with TCP in terms of predictive region tightness, whereas it has a vast advantage when it comes to computational efficiency.Finally, a comparison with Gaussian Process Regression (GPR) demonstrated that our methods produce almost as tight predictive regions as those of GPR when the correct prior is known, while GPR may produce misleading regions on real world data on which the required prior knowledge is not available.
The main future direction of this work is the development of normalized nonconformity measures like the ones presented in this paper based on other popular regression techniques, such as Ridge Regression and Support Vector Regression.Although in the case of Ridge Regression one such measure was already defined for ICP (Papadopoulos et al., 2002a), it unfortunately cannot be used with the TCP approach; thus there is potentially a considerable performance gain to be achieved from a definition of this kind for TCP.Moreover, an equally important future aim is the application of our methods to medical or other problems where the provision of predictive regions is desirable, and the evaluation of their results by experts in the corresponding field.

Figure 1 :Figure 2 :Figure 4 :Figure 5 :
Figure 1: Predictive region width distribution for the Boston housing data set.

Table 1 :
Main characteristics and experimental setup for each data set.

Table 2 :
The tightness and reliability results of our methods on the Boston Housing data set.

Table 3 :
The tightness and reliability results of our methods on the Abalone data set.

Table 4 :
The tightness and reliability results of our methods on the Computer Activity data set.

Table 5 :
The tightness and reliability results of our methods on the Kin data set.

Table 6 :
The tightness and reliability results of our methods on the Bank data set.

Table 7 :
The tightness and reliability results of our methods on the Pumadyn data set.

Table 9 :
Comparison of our methods with Gaussian Process Regression on artificial data generated by a Gaussian Process.

Table 10 :
The tightness and reliability results of Gaussian Process Regression on the Boston Housing data set.

Table 11 :
The tightness and reliability results of Gaussian Process Regression on the Abalone data set.

Table 12 :
The tightness and reliability results of Gaussian Process Regression on the Computer Activity data set.