Classify data points using K-Nearest Neighbors with average distance calculation.
| ID | X | Y | Class | Action |
|---|---|---|---|---|
| 1 | 2 | 3 | A | |
| 2 | 3 | 2 | A | |
| 3 | 3 | 4 | A | |
| 4 | 5 | 3 | A | |
| 5 | 7 | 8 | B | |
| 6 | 8 | 7 | B | |
| 7 | 8 | 9 | B | |
| 8 | 9 | 8 | B | |
| 9 | 4 | 7 | C | |
| 10 | 5 | 8 | C | |
| 11 | 3 | 8 | C | |
| 12 | 4 | 9 | C |
Compute Euclidean distance from test point to all training points:
d = √((x₂-x₁)² + (y₂-y₁)²)Sort distances and select the K closest points.
For each class among the K neighbors, compute the average distance.
Assign the test point to the class with the minimum average distance.