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.model_selection).
Use Numpy for data processing (data initialisation, data insertion etc) and use Scikit-learn 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 non-negative integer.
This set of pairs constitutes the training set TrainS ={(x, y)_i}, i =1..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 non-negative integer.
This set of pairs constitutes the test set TestS ={(x, y)_i}, i =1..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: 1<= k <=10.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!