# 8. KNN Solved example | K Nearest Neighbor Example | KNN in Machine Learning by Vidya Mahesh Huddar

## Метаданные

- **Канал:** Mahesh Huddar
- **YouTube:** https://www.youtube.com/watch?v=C75Arp5mg6I
- **Дата:** 14.05.2026
- **Длительность:** 4:42
- **Просмотры:** 1,072
- **Источник:** https://ekstraktznaniy.ru/video/51080

## Описание

8. KNN Solved example | K Nearest Neighbor Example | KNN in Machine Learning by Vidya Mahesh Huddar

Consider the student performance training dataset of 8 instances shown in Table which describes the performance of individual students in a course and their CGPA obtained in the previous semester. 
Independent attributes are – CGPA, Assessment and Project, Target variable is ‘Result’ that takes two values ‘Pass’ or ‘Fail’. 
Based on the performance of a student, classify whether a student (6.1, 40, 5) will pass or Fail. 
Assign K = 3.

SN   CGPA   Assessment   Project   Result
1      9.2               85                   8         Pass
2      8.0               80                   7         Pass
3      8.5               81                   8         Pass
4      6.0               45                   5         Fail
5      6.5               50                   4         Fail
6      8.2               72                   7         Pass
7      5.8               38                   5    

## Транскрипт

### Segment 1 (00:00 - 04:00) []

Welcome back. In this video I will discuss how to apply K nearest neighbor algorithm to the given data set and classify the new example whether it's pass or fail. This is all example number eight. Link for the previous examples are given in the description below. This is a student performance training data set. In this we have eight instances with three attributes. Those are CGPA, assessment and project. Result is a target class with the two values. One is a pass, one more is a fail. And here we need to apply K nearest neighbor algorithm and we need to classify whether the student which contains CGP is equal to 6. 1, assessment is equal to 40 and project is equal to five will pass or fail. In this we will consider K is equal to three. In the first step of K nearest neighbor algorithm, we need to find the distance between the test instance and training instances. If you have two data points with the coordinates X1 Y1 Z1 and X2 Y2 Z2, to find the distance we need to use a Euclidean distance formula which is equal to square root of X2 minus X1 bracket square plus Y2 minus Y1 bracket square plus Z2 minus Z1 bracket square. First we'll calculate the distance with the first instance. In this new instance data will be considered as X1, Y1 and Z1 and first instance data will be considered as X2, Y2 and Z2. So as per the Euclidean distance formula which is equal to square root of X2 minus X1 bracket square which is equal to 9. 2 - 6. 1 bracket square plus y2 - y1 bracket square which is equal to 85 - 40 bracket square plus z2 - z1 bracket square which is equal to 8 - 5 bracket square. So once you simplify this one, the d1 is equal to 45. 20. Next we will calculate the distance with the instant two. In this case, the instant two points will be x2, y2 and z2. As per Euclidean distance formula, which is equal to square root of 8 - 6. 1 bracket square plus 80 - 40 bracket square plus 7 - 5 bracket square. So which is equal to 40. 09. Similarly, we need to find the distances with the third instance and fourth instances. Once you find the distance with the third instance, we will get a distance as 41. 83 and a distance with the fourth instance is five. So that is what I have written here. Next we need to find the distance with the fifth instance, which is equal to 10. 05 and distance with the sixth instance, which is equal to 32. 13. So similarly, we need to find the distance with the instant seven, which is equal to 2. 02 and distance with the instant eight, which is equal to 51. 23. Once you find all the distances, next we need to arrange these distances in a ascending order. So once you arrange this one in the ascending order, we will get the minimum value at the top and maximum value at the bottom. So this is how the arrangement will looks like. As we already know that k is equal to three, it means that we need to select the nearest neighbors. So, three nearest neighbors are 2. 02, 5, and 10. 5. That is what I have written here. So, after that, we need to find the majority class. So, here we can see that all three examples are fail only. It means that majority class, which is equal to fail. If the majority class equal to fail, it means that the new student classified as a fail. So, this is how we can apply the K-nearest neighbor algorithm to the data set, and we can classify the new instance into one of the class, like a pass or fail. I hope the concept is clear. If you like the video, do like and share with your friends. Press the subscribe button for more videos. Press the bell icon for regular updates. Thank you for watching.
