Okay, for kn classification. So, we have a data set here, then we have other data points, then we have a data this yellow square that we want to predict or classify. So, for KNN algorithm, so, we will calculate all the distances between these yellow square and other data points then we will set a K that k maybe to tree. So, if k equal to tree we select a tree data points that is a or had the nearest distance from the data points to the yellow square here. So, when k equal to tree we will select a tree nearest data point. So, our In this case, we have a one rate star to green triangle.
So, we have two green triangle and one red star. So, two green triangle have a higher number. So these yellow square is being predicted classifiers green triangle. So if we set our k equal to seven, we will select the data points around seven data points arrows to the yellow square. So we have four races star tree green triangle. So for Red Star tree green triangle, so Raisa has a higher number.
So these are yellow squares being predictable classifiers are rista. So four key and this is post sudoko. So you loaded data initialized okay. So for getting the free data class, we iterate from all the data, calculate the distance between the data to the predict row and each row of the data set. And then we start the calculated distances, we get the top 10 kilos, no are we get a top kilos, then we get the most frequent cross and we return the most frequent Cross has to predict across. So if we want to know why is the K value wise the best k value for the training data, we can actually use some of the training data to train the KNN model.
Then, we also use some of the training data to actually test them all day and get the accuracy or the error. So we These are two graph here. We have a CV trained a model to k equal to 10. Then we have an era of around one. So k equal to 10. We have a era of 10 here.
So, if k is equal to 20, we have a era of around 1.3 k equal to 20. Here we have an era of aah, aah, pity. So let's say we want to choose the K value for myself I have chosen around 10 or maybe be higher or lower. Okay, so this is the KNN classification algorithm.