So, i was learning the KNN Algorithm and there i learnt cross Validation to find a optimal value of k.Now i want to apply grid search to get the optimal value.I found an answer on stack overflow where both standardScaler and KNN are passed as estimator.
pipe = Pipeline([
('sc', StandardScaler()),
('knn', KNeighborsClassifier(algorithm='brute'))
])
params = {
'knn__n_neighbors': [3, 5, 7, 9, 11] # usually odd numbers
}
clf = GridSearchCV(estimator=pipe,
param_grid=params,
cv=5,
return_train_score=True) # Turn on cv train scores
clf.fit(X, y)
My questions
I am already applying the standardscaler to standardize the data before passing to KNN. So here do i still need to pass the standardscaler in the estimator?
why X and Y are passed instead of x_train and y_train assuming x and y are independent and dependent variable and x_train,y_train are formed after train_test_split operation ?
Any example of such code will be appericiated.