Since kNN handles both training and prediction at the RAM level and requires no explicit training process, what exactly happens when a knn model is being fitted? I thought this step was related to training the model. Thank you.
Here is the error I will get if I skip fitting step.
NotFittedError: This KNeighborsClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
Sample Code:
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
f=r"aug_train.csv"
df=pd.read_csv(f)
X=df[:90000][["training_hours", "city_development_index"]].values
y=df[:90000]["target"].values
X_train, X_test, y_train, y_test=train_test_split(X,y)
knn=KNeighborsClassifier(n_neighbors=2)
knn.fit(X_train, y_train)
yhat=knn.predict(X_test)
print(yhat)