Nearest neighbors classifier. Note: if there is a tie for the most common label among the neighbors, then the predicted label is arbitrary.
| 53 | |
| 54 | |
| 55 | class KNNClassifier(KNNBase): |
| 56 | """Nearest neighbors classifier. |
| 57 | |
| 58 | Note: if there is a tie for the most common label among the neighbors, then |
| 59 | the predicted label is arbitrary.""" |
| 60 | |
| 61 | def aggregate(self, neighbors_targets): |
| 62 | """Return the most common target label.""" |
| 63 | |
| 64 | most_common_label = Counter(neighbors_targets).most_common(1)[0][0] |
| 65 | return most_common_label |
| 66 | |
| 67 | |
| 68 | class KNNRegressor(KNNBase): |