Question: Create a Python Program, provide codes and detailed explanation at each step. Goal: Create a mini but functional kNN classifier with hyperparameter search ( specifically
Create a Python Program, provide codes and detailed explanation at each step.
Goal:
Create a mini but functional kNN classifier with hyperparameter search specifically use GridSearchCV in sklearn.modelselection
Use Numpy for data processing data initialisation, data insertion etc and use Scikitlearn library for machine learning part.
The program asks the user for input N positive integer and reads it
Then the program asks the user to provide N x y pairs one by one and reads all of them: first: x value, then: y value for every pair one by one.
X is treated as the input feature and Y is treated as the class label. X is a real number, Y is a nonnegative integer.
This set of pairs constitutes the training set TrainS x yi i N
Then the program asks the user for input M positive integer and reads it
Then the program asks the user to provide M x y pairs one by one and reads all of them: first: x value, then: y value for every pair one by one.
X is treated as the input feature and Y is treated as the class label. X is a real number, Y is a nonnegative integer.
This set of pairs constitutes the test set TestS x yi i M
In the end, the program outputs: thebest kfor the kNN Classification method and thecorresponding test accuracy.
kNN Classifier should be trained on pairs from TrainS, tested on x values from TestS and compared with y values from TestS.
Try the following range of k: k
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
