12/10/26 Mon 15:38pm

KNN / K Nearest Neighbour Algorithm

It is a widely used Machine Learning algorithm for classification and regression tasks.
It works by identifying the K closest data points to the given inputs and making prediction based on the majority class or average value of those neighbours.

Steps to implement KNN

  1. Select the value of for prediction
  2. Calculate Euclidian Distance from the stored dataset
  3. Find the K nearest neighbour, the smallest euclidian distance
  4. Apply majority voting for classification (or) taking average for regression

Q&A

Question

A transformer predicts oil temperature after 10 minutes using present loading and present oil temperature. The historic data is given below,
using K = 3 Predict the temperature after 10 minutes if the present loading is 75% and present temp is 62

PointLoading %Present TemperatureTemperature after 10 minutes
A505052
B605558
C706064
D806570
E907076
Solution:
Calculate the distance using the euclidian distance formula

Question

A pump uses two features as vibration and as flow deficit the following historical data is given below.
Classify new observation (4,3) using K=3

Data PointCondition of Pump
A11Normal
B21Normal
C33Bearing Fault
D44Bearing Fault
E15Blockage

Manhattan Distance