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