|
|
| ALGORITHM 2: K-nearest neighbor pseudocode. |
|
|
| Input: Dataset D= { (x1,c1),…,(xN,cN) }, and unlabeled instance x=(x1,…,xN). |
| Output: predicted class Ci. |
| for each classified example (xi,ci) do |
| calculate distance d(xi,x) |
| order d(xi,x) from lowest to highest |
| select k nearest neighbors to x |
| vote for majority class among k neighbors, Ci |
| return Ci. |
| end |
|
|