Model Pipeline - K-Nearest Neighbors (KNN)
K-Nearest Neighbors (KNN) is a simple way to classify data points by looking at the closest examples in the training data. It finds the 'k' nearest neighbors and decides the class by majority vote.
K-Nearest Neighbors (KNN) is a simple way to classify data points by looking at the closest examples in the training data. It finds the 'k' nearest neighbors and decides the class by majority vote.
N/A (KNN is a lazy learner and does not have training epochs)
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | N/A | 0.90 | KNN does not train with epochs; accuracy shown on test set with k=3 |
X = [[1, 2], [2, 3], [3, 4], [6, 7]]
y = ['A', 'A', 'B', 'B']
from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors=3) knn.fit(X_train, y_train) preds = knn.predict(X_test) print(preds)
Pass the test and this pattern moves unknown