Lab 10 - Manual and Assignment On KNN
Lab 10 - Manual and Assignment On KNN
Objective:
Understand and implement k-Nearest Neighbours (k-NN).
Task:
- Load the Iris dataset using Scikit-learn.
Step-by-Step Implementation:
```python
from sklearn import datasets
import numpy as np
data = datasets.load_iris()
X = data.data
y = data.target
```
```python
from collections import Counter
from scipy.spatial import distance
def euclidean_distance(x1, x2):
return np.sqrt(np.sum((x1 - x2) ** 2))
class KNN:
def __init__(self, k=3):
self.k = k
```python
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
knn = KNN(k=5)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
4. What other distance metrics can be used instead of Euclidean distance, and how do
they impact classification?
5. How does the choice of train-test split ratio affect the model’s performance?