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

KNN Example

The document describes a K-Nearest Neighbors (KNN) classification process for a fruit dataset based on weight, sweetness, and color intensity. It outlines the steps to calculate Euclidean distances for each fruit, identify the three nearest neighbors, and perform majority voting to classify a new fruit as 'Orange.' Key takeaways include the effectiveness of KNN for small datasets and its limitations regarding speed and sensitivity to data scaling.

Uploaded by

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

KNN Example

The document describes a K-Nearest Neighbors (KNN) classification process for a fruit dataset based on weight, sweetness, and color intensity. It outlines the steps to calculate Euclidean distances for each fruit, identify the three nearest neighbors, and perform majority voting to classify a new fruit as 'Orange.' Key takeaways include the effectiveness of KNN for small datasets and its limitations regarding speed and sensitivity to data scaling.

Uploaded by

wilsonabi2406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Imagine we have a fruit dataset with the following features: © @ Weight (grams) > X) « @ Sweetness level (1-10) = X) © @ Color intensity (1-10) — X3 © @ Fruit type | The label (Apple @ or Orange @) BH Dataset: Fruit Weight (9) Sweetness Color Intensity Fruit Type A 150 6 a Apple 8 170 5 6 G Aople c 140 7 7 Apple D 200 4 5 orange E 210 3 4 B orange Classify a new fruit with the following features: « Weight = 180g « Sweetness =4 ¢ Color Intensity =5 « Use K = 3 — We will find the 3 nearest neighbors. Step 1: Use the Euclidean Distance Formula The Euclidean distance formula for 3 variables is: Distance = 4/(X; 1)? + (Xe — X} P+ (Xa — X3)? Where: © X, Xp, X3— Features of the new fruit « Xj, X}, X4 > Features of each fruit in the dataset. Step 2: Calculate the Distance for Each Fruit @ For Fruit A: X, = 150, X, = 6, X, =8 Distance = /(U80= 150" + (F= OF + (= 8F = VBP + (AP + (3 = V900 F449 = V913 ~ 30.2 For Fruit B: X1 = 170, Xo = 5, X3 =6 Distance = y/(180—- 170 + (4-5 + (5-6 = VG0P + (1 + (1 = VI00FTF1 = VI02 +101 @ For Fruit c: X1 = 140, Xo = 7,X3=7 Distance = /(80— 140? + (G-7) +67)? = VRE CSF = 16004944 = VI6I3 40.2 @ For Fruit D: Xy = 200, Xp = 4,.X3 =5 Distance = (180 — 200)" + (4-4)? + (5-5 = v(-20 + (0 + 0 = V00+040 = V400 = 20 For Fruit E: X, = 210, Xp = 3, Xy =4 Distance = \/(180 — 210)? + (4-3) + (5-4 = ¥(-30P + 0 + OF = Y900+141 = V902 x 30.0 Step 3: Identify the 3 Nearest Neighbors Let's list the distances: Fruit Distance Fruit Type B 10.1 G Apple D 200 Borange E 30.0 Borange a 302 © Apple c 402 F Apple The 3 nearest neighbors (smallest distances) are: © B(Apple) > 10.1 = D(Orange) —- 20.0 « E (Orange) — 30.0 Step 4: Perform Majority Voting Count the labels of the 3 nearest neighbors: © 6 Apple — 1 neighbor © @ Orange — 2 neighbors Since Orange appears more frequently, the new fruit is classified as: Mo oOrange Key Takeaways 1. KNN Clas: ication Process: © Compute the Euclidean distance for all data points. © Select the K nearest neighbors. © Use majority voting to determine the class. 2. Why KNN works wel © Itis simple and effective for small datasets. © It works well with multi-dimensional data (e.g., 3 independent variables). 3. Limitations: © KNN can be slow with large datasets. © It is sensitive to the choice of K and scaling of data.

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