| 49 | } |
| 50 | |
| 51 | array knn(array &train_feats, array &test_feats, array &train_labels) { |
| 52 | // Find distances between training and testing sets |
| 53 | array dist = distance(train_feats, test_feats); |
| 54 | |
| 55 | // Find the neighbor producing the minimum distance |
| 56 | array val, idx; |
| 57 | min(val, idx, dist); |
| 58 | |
| 59 | // Return the labels |
| 60 | return train_labels(idx); |
| 61 | } |
| 62 | |
| 63 | void knn_demo(bool console, int perc) { |
| 64 | array train_images, train_labels; |