Question: The algorithm for KNN classification model is given below: Algorithm: KNearestNeighbors , Input: , Training data x , , Training , , data labels ,

The algorithm for KNN classification model is given below:
Algorithm: KNearestNeighbors
,Input: , Training data x
,,Training
,,data labels
,,Y Sample x
,,to classify
,Output: Decision yp about sample x
,for ilarr1 to m do
,,Compute distance between training sample and
,,unlabeled sample x i.e.d(,x)
,end for
Compute set I containing the indices for the k smallest distances d(xi,x) Compute the decision class y pby measuring the majority
label Y from I return y p
Task 1
Write a program to implement KNN classifier on heart_statlog_cleveland_hungary_data and classify given dataset.
Load dataset
Perform required preprocessing on data
Split dataset into test and train sets
Perform KNN algorithm to make predictions for k=5 and (6-10) as well.
Compute accuracy and confusion matrix
Find accuracy for each value of k and display and for 3 different splits as 30:70,20:80,10:90
Find the best k which gives highest value of accuracy and worst k which gives worst accuracy
Also compute confusion matrix for both best and worst value of k.
The algorithm for KNN classification model is

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 Programming Questions!