KNN Solved Example Diabetic Patient

 
Video Tutorials
Artificial Intelligence Tutorial
Machine Learning Projects TutorialPython Video tutorial
Computer Graphics Video TutorialC++ Video Tutorial
Big Data Analytics Video TutorialSoft Computing Video Tutorial
Placement Video TutorialJava Video Tutorial

KNN Solved Example to predict Sugar of Diabetic Patient given BMI and Age

Apply K nearest neighbor classifier to predict the diabetic patient with the given features BMI, Age. If the training examples are,

BMIAgeSugar
33.6501
26.630O
23.440O
43.167O
35.3231
35.9671
36.7451
25.746O
23.329O
31561

Assume K=3,

Test Example BMI=43.6, Age=40, Sugar=?

Solution:

Video Tutorial

The given training dataset has 10 instances with two features BMI (Body Mass Index) and Age. Sugar is the target label. The target label has two possibilities 0 and 1. 0 means the diabetic patient has no sugar and 1 means the diabetic patient has sugar.

Given the dataset and new test instance, we need to find the distance from the new test instance to every training example. Here we use the euclidean distance formula to find the distance.

 euclidean distance formula

In the next table, you can see the calculated distance from text example to training instances.

BMIAgeSugarFormulaDistance
33.6501√((43.6-33.6)^2+(40-50)^2 )14.14
26.630O√((43.6-26.6)^2+(40-30)^2 )19.72
23.440O√((43.6-23.4)^2+(40-40)^2 )20.20
43.167O√((43.6-43.1)^2+(40-67)^2 )27.00
35.3231√((43.6-35.3)^2+(40-23)^2 )18.92
35.9671√((43.6-35.9)^2+(40-67)^2 )28.08
36.7451√((43.6-36.7)^2+(40-45)^2 )8.52
25.746O√((43.6-25.7)^2+(40-46)^2 )18.88
23.329O√((43.6-23.3)^2+(40-29)^2 )23.09
31561√((43.6-31)^2+(40-56)^2 )20.37

Once you calculate the distance, the next step is to find the nearest neighbors based on the value of k. In this case, the value of k is 3. Hence we need to find 3 nearest neighbors.

BMIAgeSugarDistanceRank
33.650114.142
26.630O19.72
23.440O20.20
43.167O27.00
35.323118.92
35.967128.08
36.74518.521
25.746O18.883
23.329O23.09
3156120.37

Now, we need to apply the majority voting technique to decide the resulting label fro the new example. Here the 1st and 2nd nearest neighbors have target label 1 and the 3rd nearest neighbor has target label 0. Target label 1 has the majority. Hence the new example is classified as 1, That is the diabetic patient has Sugar.

Test Example BMI=43.6, Age=40, Sugar=1

Summary

Here you can find the solution to the KNN Example to predict the Sugar of Diabetic Patients given BMI and Age. If you like the material share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *