0% found this document useful (0 votes)
4 views6 pages

Lab 3

The document outlines an experiment for a BS Biomedical Engineering lab focusing on the K-Nearest Neighbor (K-NN) algorithm. It describes the objectives of familiarizing students with K-NN and its implementation on datasets, along with a step-by-step explanation of how the algorithm works. Additionally, it includes a lab task to apply the KNN model on two datasets and test it with five different values of K.

Uploaded by

Samiullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Lab 3

The document outlines an experiment for a BS Biomedical Engineering lab focusing on the K-Nearest Neighbor (K-NN) algorithm. It describes the objectives of familiarizing students with K-NN and its implementation on datasets, along with a step-by-step explanation of how the algorithm works. Additionally, it includes a lab task to apply the KNN model on two datasets and test it with five different values of K.

Uploaded by

Samiullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of Mechatronics

Engineering
Air University, Islamabad, Pakistan

Program: BS Biomedical Engineering Semester:


Subject Machine Learning Lab Date: …………….

Experiment 3: Introduction to K-Nearest Neighbor Algorithm and its implementation.


OBJECTIVES:

1. To become familiar with K-Nearest Neighbor Algorithm.


2. To understand how to implement KNN on dataset .

Name: Roll no:

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtained Marks Obtained
Ability to 5 Organization/Structure 5
conduct
Experiment
Data Analysis & 5 Results 5
Interpretation
Total Marks obtained
Remarks (if any)………………………………………………..

Name & Signature of faculty: …………………………………


K-Nearest Neighbor Algorithm
Introduction

K-Nearest Neighbour is one of the simplest Machine Learning algorithms based on Supervised Learning
technique. K-NN algorithm assumes the similarity between the new case/data and available cases and put the
new case into the category that is most similar to the available categories.

K-NN algorithm stores all the available data and classifies a new data point based on the similarity. This
means when new data appears then it can be easily classified into a well suite category by using K- NN
algorithm.

How does K-NN work?

The K-NN working can be explained on the basis of the below algorithm:

o Step-1: Select the number K of the neighbors


o Step-2: Calculate the Euclidean distance of K number of neighbors
o Step-3: Take the K nearest neighbors as per the calculated Euclidean distance.
o Step-4: Among these k neighbors, count the number of the data points in each category.
o Step-5: Assign the new data points to that category for which the number of the neighbor is
maximum.
o Step-6: Our model is ready.

Suppose we have a new data point and we need to put it in the required category. Consider the below image:
o Firstly, we will choose the number of neighbors, so we will choose the k=5.
o Next, we will calculate the Euclidean distance between the data points. The Euclidean distance is the
distance between two points, which we have already studied in geometry. It can be calculated as:

o By calculating the Euclidean distance we got the nearest neighbors, as three nearest neighbors in
category A and two nearest neighbors in category B. Consider the below image:
o As we can see the 3 nearest neighbors are from category A, hence this new data point must belong to
category A.

Code
Lab Task

Apply KNN model on two different dataset and test it on 5 different values of K.

You might also like