0% found this document useful (0 votes)
25 views4 pages

KNN Activity

The document summarizes the KNN algorithm in 3 steps: 1. The KNN algorithm makes predictions based on similarity between data by finding the K-nearest neighbors of the data point we want to predict. 2. It calculates the distance between the point and all other data points to identify the K-nearest neighbors. 3. It then predicts the classification or regression value based on the class or mean value of those K-nearest neighbors.

Uploaded by

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

KNN Activity

The document summarizes the KNN algorithm in 3 steps: 1. The KNN algorithm makes predictions based on similarity between data by finding the K-nearest neighbors of the data point we want to predict. 2. It calculates the distance between the point and all other data points to identify the K-nearest neighbors. 3. It then predicts the classification or regression value based on the class or mean value of those K-nearest neighbors.

Uploaded by

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

KNN algorithm for prediction

Assel Kaiyrbek,

College of Business, Westcliff University

MTH600

Professor Mwanza
Introduction

The k- Nearest neighborhood (KNN)- is a machine learning algorithm which is used for
classification and regression tasks. It makes predictions based on similarity between data. The
idea of KNN is that data which are close to each other likely have similar characteristics (Robert
T 202.)

Below I’d like to explain KNN step by step:

1. Data preparation

You have a dataset which consists of attributes and classification or regression.

2. Choose the number of neighborhood (K).

You need to choose k. Which is the number of nearest neighborhoods for consideration when
make a prediction. Smaller k less smooth than larger k to predictions.

3. Calculate distance

d=√((x2 – x1)² + (y2 – y1)²).

4. Find the KNN

Select the smallest distance which is k data point you want to predict for.

5. Classification or Regression

In the case of classification tasks, choose the label which is most common to KNN. In case of
regression, calculate the average of the main values of the KNN.

6. Make prediction.

Example

You have an apple and banana, and they have features “weight” and “color”. You want to
classify a new fruit which is based on weight and color.

Data:

1. Apple – 150gr, Red


2. Apple – 120gr, Red
3. Banana – 130gr, Yellow
4. Banana – 160gr, Yellow

You want to classify a fruit which is (140g,red). K=3 (Murphy 2005).

1. Calculate distance.

1. d=√((150 – 140)² + (red – red)²= 10

2. d=√((120 – 140)² + (red – red)²= 20


3. d=√((130 – 140)² + (yellow – red)²=10.05

4. d=√((160 – 140)² + (yellow – red)²=20.1

2. we need to find 3 nearest neighbors with the smallest distances:

1=10, 3=10.05, 2= 20.

3. two of them are apples and one banana, which means prediction is APPLE.

Conclusion

Based on this example we found that KNN algorithm predicts that the fruit is an APPLE.
References

1. "Introduction to Decision Analysis" by Robert T 2021 . Clemen, 300-311.

2. KNN Algorithm in python and Scikit-learn (real python) https://realpython.com/k-nearest-


neighbors-algorithm-python/

3. An introduction to KNN (GeeksforGeeks) https://www.geeksforgeeks.org/k-nearest-


neighbours/

4. Machine learning: a probabilistic perspective. By Kevin P.Murphy. 2005. Murphy, 130-146.

5. Understanding the KNN. (YouTube - StatQuest with Josh Starmer)

6. Bowerman, B. (2018). Business Statistics in Practice: Using Data, Modeling, and


Analytics (9th ed.). McGraw-Hill Higher Education (US).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy