A kNN Example for Interpolation


Using the same training data and the same technique, we can also do kNN for smoothing (interpolation between values).

Thus, our data is shown as

Suppose we know the X data is between 0 and 6 and we would like to compute the value of Y between them.
  1. We define dx=0.1 and set the value of x=0 to 6 with increment dx.
  2. Compute distance between x (as if it is the query instance) and each of the data X. For instance the distance between query instance x=0.1 and X2=1.2 is denoted as d(x,X2)=|0.1–1.2|=1.1 .

    Similarly, distance between query instance x=0.5 and X5=5.1 is computed as d(x,X5)=|0.5-5.1|=4.6. The table shows distance for x=0 to 0.5 for all X data.

  3. We obtain the nearest neighbors based on the Kth minimum distance and copy the value of Y of the nearest neighbors.
  4. The smoothing estimate is the arithmetic average of the values of the nearest neighbors.
The table shows example of computation of KNN for smoothing for x = 2.5 until 3.5 and K=4.




      Gerald used to be one of the most logical people I know.    
      Now he is mad as a hatter (mentally ill).