A kNN Numerical Example (Cont.)

  1. Sort the distance and determine nearest neighbors based on the Kth minimum distance.

    X1=Acid Durability (seconds) X2=Strength (kg/m2) Square distance to query instance (3,7) Rank minimum distance Is it included in 3-nearest neighbors?
    7 7 (7-3)2+(7-7)2=16 3 Yes
    7 4 (7-3)2+(4-7)2=25 4 No
    3 4 (3-3)2+(4-7)2=9 1 Yes
    1 4 (1-3)2+(4-7)2=13 2 Yes

  2. Gather the category Y of the nearest neighbors.
    Notice in the second row last column that the category of nearest neighbor (Y) is not included because the rank of this data is more than 3.

    X1=Acid Durability (seconds) X2=Strength (kg/m2) Square distance to query instance (3,7) Rank minimum distance Is it included in 3-nearest neighbors? Category of nearest neighbor
    7 7 (7-3)2+(7-7)2=16 3 Yes Bad
    7 4 (7-3)2+(4-7)2=25 4 No
    3 4 (3-3)2+(4-7)2=9 1 Yes Good
    1 4 (1-3)2+(4-7)2=13 2 Yes Good

  3. Use simple majority of the category of nearest neighbors as the prediction value of the query instance.
    We have 2 good and 1 bad, since 2>1 then we conclude that a new paper tissue that passed laboratory test with X1=3 and X2=7 is included in Good category.