Miss Erum Mahood Topic: KNN Algorthim: Presentator BY: Zobia Malaika Maryam Minahil
Miss Erum Mahood Topic: KNN Algorthim: Presentator BY: Zobia Malaika Maryam Minahil
TOPIC :
KNN ALGORTHIM
PRESENTATOR
BY:
ZOBIA
MALAIKA
MARYAM
K-Nearest Neighbors (KNN) is a simple way to classify things by
looking at what’s nearby. Imagine a streaming service wants to
predict if a new user is likely to cancel their subscription
(churn) based on their age. They checks the ages of its existing
users and whether they churned or stayed. If most of the “K”
closest users in age of new user canceled their subscription
KNN will predict the new user might churn too. The key idea
is that users with similar ages tend to have similar
behaviors and KNN uses this closeness to make decisions.
Getting Started with K-Nearest Neighbors:
• K-Nearest Neighbors is also called as a lazy learner
algorithm because it does not learn from the training set
immediately instead it stores the dataset and at the time of
classification it performs an action on the dataset.
• As an example, consider the following table of data points
containing two features:
The new point is classified as Category 2 because most of
its closest neighbors are blue squares. KNN assigns the
category based on the majority of nearby points.
The image shows how KNN predicts the category of a new
data point based on its closest neighbours.
• The red diamonds represent Category 1 and the blue
squares represent Category 2.
Euclidean distance is defined as the straight-line distance between two points in a plane or
space. You can think of it like the shortest path you would walk if you were to go directly
from one point to another.
distance(x,Xi)=∑j=1d(xj–Xij)2]distance(x,Xi)=∑j=1d(xj–Xij)2]
2. Manhattan Distance
This is the total distance you would travel if you could only move along horizontal
and vertical lines (like a grid or city streets). It’s also called “taxicab distance”
because a taxi can only drive along the grid-like streets of a city.
d(x,y)=∑i=1n∣xi−yi∣d(x,y)=∑i=1n∣xi−yi∣
3. Minkowski Distance
• K represents the number of nearest neighbors that needs to be considered while making
prediction.
Step 2: Calculating distance
• To measure the similarity between target and training data points Euclidean
distance is used. Distance is calculated between data points in the dataset and
target point.
Step 3: Finding Nearest Neighbors
• The k data points with the smallest distances to the target point are nearest
neighbors.
Step 4: Voting for Classification or Taking Average for Regression
• When you want to classify a data point into a category (like spam or not spam), the K-NN
algorithm looks at the K
closest points in the dataset. These closest points are called neighbors. The algorithm then
looks at which category
the neighbors belong to and picks the one that appears the most. This is called majority
voting.
Advantages and Disadvantages of the KNN Algorithm
Advantages:
• Easy to implement: The KNN algorithm is easy to implement because
its complexity is relatively low as compared to other machine learning
algorithms.