SlideShare a Scribd company logo
KNN
Amir Shokri
1399/10/07
KNN
Introduction::
K-nearest neighbors is a lazy learning instance based classification algorithm which is widely implemented in
both supervised and unsupervised learning techniques.
Lazy Learning as it doesn’t learn from discriminative function from training data but memorizes training
dataset.
this technique implements classification by considering majority of vote among the “k” closest points to the
unlabeled data point.
It works on unseen data and will search through the training dataset for the k-most similar instances.
Euclidean distance / Hamming distance is used as metric for calculating the distance between points.
Amir Shokri
KNN
Euclidean Distance::
𝒅𝒊𝒔𝒕 𝒙, 𝒚 , 𝒂, 𝒃 = 𝒙 − 𝒂 𝟐 + 𝒚 − 𝒃 𝟐 )
Amir Shokri
KNN
Hamming Distance::
Onforone oneandone -> 3
11010110110 1100111110 -> 2
Amir Shokri
KNN
Green circle = ?
K = 3
Closest 3 points taken
2 -> orange
1 -> blue
2 orange > 1 blue
Green circle is a orange triangle
Amir Shokri
?
K = 3
KNN
Green circle = ?
K = 5
Closest 5 points taken
2 -> orange
1 -> blue
2 orange < 3 blue
Green circle is a blue square
Amir Shokri
?
K = 5
KNN
Green circle = ?
k = 1 : orange
K = 3 : orange
K = 5 : orange
K = 7 : blue
K = 9 : orange
Amir Shokri
KNN
Choosing value of “K”
• “k” should be large so that error rate is minimized “k” too small will lead to noisy decision boundaries
• “k” should be small enough so that only nearby samples are included “k” too large will lead to over-
smoothed boundaries
• Setting “k” to the square root of the number of training samples can lead to better results.
No Of features = 20
𝑘 = 20 = 4.4 ~ 4
Amir Shokri
KNN
Amir Shokri
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0 10 20 30 40 50 60 70 80
“k” values vs error curve
KNN
Amir Shokri
0
10
20
30
40
50
60
0 10 20 30 40 50 60
“k” values vs validation error curve
Minimum error
Best value of “k”
KNN
Pros.
• Non complex and very easy to understand and implement.
• Useful for non linear data as no assumptions about data.
• High accuracy (relatively), but no competitive compared to supervised learning algorithms.
• Can be used both for classification or regression.
• Best used where the probability distribution is unknown.
Amir Shokri
KNN
Cons.
• Computationally expensive.
• Lot of space is consumed as all the data points are stored.
• Sensitive to irrelevant features and the scale of the data.
• Output purely depends on k value chosen by user which can reduce accuracy for some values.
Amir Shokri
KNN
Applications.
• Recommender systems
• Medicine
• Finance
• Text mining
• agriculture
Amir Shokri
KNN
Amir Shokri
voronoi diagram
KNN
Bias : miss relevant relations within the data; everything gets skewed into specific classes -> underfitting.
Variance : too may hypotheses results in hallucination patterns -> overfitting
How To verify ? Split data in a test and training set
Amir Shokri
KNN
Bias : miss relevant relations within the data; everything gets skewed into specific classes -> underfitting.
Variance : too may hypotheses results in hallucination patterns -> overfitting
How To verify ? Split data in a test and training set
Amir Shokri
KNN
Will nearest-neighbours have high bias or high variance ?
-> high variance !
• Every instance is an hypothesis : the decision boundary is very/too detailed
• How can we solve this?
• How to smooth the data obtain a more general model?
• K-nearest neighbours (knn)
• Weighted average
• Prototypes
• Locally weighted regresson
Amir Shokri
KNN
• For some value k take the k nearest neighbors of the new instance, and predict the class that is most
common among these k neighbors
• Alleviates overfitting to a certain degree
• Smoother decision boundaries
• Influence of outliers is attenuated
Amir Shokri
KNN
• What should k be ?
• Too low: overfitting
• Too high : underfitting
• Strategies:
• Cross-validation
• Heuristics
• algorithms
Amir Shokri

More Related Content

What's hot

K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)
Abdullah al Mamun
 
K - Nearest neighbor ( KNN )
K - Nearest neighbor  ( KNN )K - Nearest neighbor  ( KNN )
K - Nearest neighbor ( KNN )
Mohammad Junaid Khan
 
K Nearest Neighbor Presentation
K Nearest Neighbor PresentationK Nearest Neighbor Presentation
K Nearest Neighbor Presentation
Dessy Amirudin
 
Knn
KnnKnn
Decision Tree - C4.5&CART
Decision Tree - C4.5&CARTDecision Tree - C4.5&CART
Decision Tree - C4.5&CARTXueping Peng
 
KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...
KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...
KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...
Simplilearn
 
K-Nearest Neighbor Classifier
K-Nearest Neighbor ClassifierK-Nearest Neighbor Classifier
K-Nearest Neighbor Classifier
Neha Kulkarni
 
K MEANS CLUSTERING
K MEANS CLUSTERINGK MEANS CLUSTERING
K MEANS CLUSTERING
singh7599
 
KNN - Classification Model (Step by Step)
KNN - Classification Model (Step by Step)KNN - Classification Model (Step by Step)
KNN - Classification Model (Step by Step)
Manish nath choudhary
 
Reinforcement Learning : A Beginners Tutorial
Reinforcement Learning : A Beginners TutorialReinforcement Learning : A Beginners Tutorial
Reinforcement Learning : A Beginners Tutorial
Omar Enayet
 
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Simplilearn
 
Knn Algorithm
Knn AlgorithmKnn Algorithm
Knn Algorithm
Kamal Gupta Roy
 
k Nearest Neighbor
k Nearest Neighbork Nearest Neighbor
k Nearest Neighborbutest
 
Support Vector Machines
Support Vector MachinesSupport Vector Machines
Support Vector Machinesnextlib
 
Density based clustering
Density based clusteringDensity based clustering
Density based clustering
YaswanthHariKumarVud
 
Data Science: Applying Random Forest
Data Science: Applying Random ForestData Science: Applying Random Forest
Data Science: Applying Random Forest
Edureka!
 
Convolutional Neural Networks : Popular Architectures
Convolutional Neural Networks : Popular ArchitecturesConvolutional Neural Networks : Popular Architectures
Convolutional Neural Networks : Popular Architectures
ananth
 
Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...
Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...
Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...
Simplilearn
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
Simplilearn
 

What's hot (20)

K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)
 
K - Nearest neighbor ( KNN )
K - Nearest neighbor  ( KNN )K - Nearest neighbor  ( KNN )
K - Nearest neighbor ( KNN )
 
K Nearest Neighbor Presentation
K Nearest Neighbor PresentationK Nearest Neighbor Presentation
K Nearest Neighbor Presentation
 
Knn
KnnKnn
Knn
 
Decision Tree - C4.5&CART
Decision Tree - C4.5&CARTDecision Tree - C4.5&CART
Decision Tree - C4.5&CART
 
KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...
KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...
KNN Algorithm - How KNN Algorithm Works With Example | Data Science For Begin...
 
K-Nearest Neighbor Classifier
K-Nearest Neighbor ClassifierK-Nearest Neighbor Classifier
K-Nearest Neighbor Classifier
 
K MEANS CLUSTERING
K MEANS CLUSTERINGK MEANS CLUSTERING
K MEANS CLUSTERING
 
K Nearest Neighbors
K Nearest NeighborsK Nearest Neighbors
K Nearest Neighbors
 
KNN - Classification Model (Step by Step)
KNN - Classification Model (Step by Step)KNN - Classification Model (Step by Step)
KNN - Classification Model (Step by Step)
 
Reinforcement Learning : A Beginners Tutorial
Reinforcement Learning : A Beginners TutorialReinforcement Learning : A Beginners Tutorial
Reinforcement Learning : A Beginners Tutorial
 
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
 
Knn Algorithm
Knn AlgorithmKnn Algorithm
Knn Algorithm
 
k Nearest Neighbor
k Nearest Neighbork Nearest Neighbor
k Nearest Neighbor
 
Support Vector Machines
Support Vector MachinesSupport Vector Machines
Support Vector Machines
 
Density based clustering
Density based clusteringDensity based clustering
Density based clustering
 
Data Science: Applying Random Forest
Data Science: Applying Random ForestData Science: Applying Random Forest
Data Science: Applying Random Forest
 
Convolutional Neural Networks : Popular Architectures
Convolutional Neural Networks : Popular ArchitecturesConvolutional Neural Networks : Popular Architectures
Convolutional Neural Networks : Popular Architectures
 
Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...
Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...
Hierarchical Clustering | Hierarchical Clustering in R |Hierarchical Clusteri...
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
 

Similar to Knn

k-Nearest Neighbors with brief explanation.pptx
k-Nearest Neighbors with brief explanation.pptxk-Nearest Neighbors with brief explanation.pptx
k-Nearest Neighbors with brief explanation.pptx
gamingzonedead880
 
K nearest neighbor: classify by closest training points.
K nearest neighbor: classify by closest training points.K nearest neighbor: classify by closest training points.
K nearest neighbor: classify by closest training points.
mcafarewell2e
 
Knn 160904075605-converted
Knn 160904075605-convertedKnn 160904075605-converted
Knn 160904075605-converted
rameswara reddy venkat
 
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
Maninda Edirisooriya
 
KNN Classifier
KNN ClassifierKNN Classifier
KNN Classifier
Mobashshirur Rahman 👲
 
Training machine learning knn 2017
Training machine learning knn 2017Training machine learning knn 2017
Training machine learning knn 2017
Iwan Sofana
 
K- Nearest Neighbor Approach
K- Nearest Neighbor ApproachK- Nearest Neighbor Approach
K- Nearest Neighbor Approach
Kumud Arora
 
K-NN K-Nearest Neighbors Algorithm.pptx
K-NN K-Nearest Neighbors Algorithm.pptxK-NN K-Nearest Neighbors Algorithm.pptx
K-NN K-Nearest Neighbors Algorithm.pptx
ssuser2624f71
 
MachineLearning.pptx
MachineLearning.pptxMachineLearning.pptx
MachineLearning.pptx
Bangtangurl
 
K Nearest neighbour
K Nearest neighbourK Nearest neighbour
K Nearest neighbour
Learnbay Datascience
 
Scalable Recommendation Algorithms with LSH
Scalable Recommendation Algorithms with LSHScalable Recommendation Algorithms with LSH
Scalable Recommendation Algorithms with LSH
Maruf Aytekin
 
k-NN Algorithm.pptx
k-NN Algorithm.pptxk-NN Algorithm.pptx
k-NN Algorithm.pptx
Mukul Kumar Singh Chauhan
 
Clustering - ACM 2013 02-25
Clustering - ACM 2013 02-25Clustering - ACM 2013 02-25
Clustering - ACM 2013 02-25
MapR Technologies
 
knn is the k nearest algorithm ppt that includes all about knn, its adv and d...
knn is the k nearest algorithm ppt that includes all about knn, its adv and d...knn is the k nearest algorithm ppt that includes all about knn, its adv and d...
knn is the k nearest algorithm ppt that includes all about knn, its adv and d...
BootNeck1
 
K nearest neighbours
K nearest neighboursK nearest neighbours
K nearest neighbours
Learnbay Datascience
 
MrKNN_Soft Relevance for Multi-label Classification
MrKNN_Soft Relevance for Multi-label ClassificationMrKNN_Soft Relevance for Multi-label Classification
MrKNN_Soft Relevance for Multi-label Classification
YI-JHEN LIN
 
09_dm1_knn_2022_23.pdf
09_dm1_knn_2022_23.pdf09_dm1_knn_2022_23.pdf
09_dm1_knn_2022_23.pdf
ArafathJazeeb1
 
Instance based learning
Instance based learningInstance based learning
Instance based learningSlideshare
 

Similar to Knn (20)

k-Nearest Neighbors with brief explanation.pptx
k-Nearest Neighbors with brief explanation.pptxk-Nearest Neighbors with brief explanation.pptx
k-Nearest Neighbors with brief explanation.pptx
 
K nearest neighbor: classify by closest training points.
K nearest neighbor: classify by closest training points.K nearest neighbor: classify by closest training points.
K nearest neighbor: classify by closest training points.
 
Knn 160904075605-converted
Knn 160904075605-convertedKnn 160904075605-converted
Knn 160904075605-converted
 
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
Lecture 11 - KNN and Clustering, a lecture in subject module Statistical & Ma...
 
KNN.pptx
KNN.pptxKNN.pptx
KNN.pptx
 
KNN Classifier
KNN ClassifierKNN Classifier
KNN Classifier
 
Training machine learning knn 2017
Training machine learning knn 2017Training machine learning knn 2017
Training machine learning knn 2017
 
K- Nearest Neighbor Approach
K- Nearest Neighbor ApproachK- Nearest Neighbor Approach
K- Nearest Neighbor Approach
 
K-NN K-Nearest Neighbors Algorithm.pptx
K-NN K-Nearest Neighbors Algorithm.pptxK-NN K-Nearest Neighbors Algorithm.pptx
K-NN K-Nearest Neighbors Algorithm.pptx
 
MachineLearning.pptx
MachineLearning.pptxMachineLearning.pptx
MachineLearning.pptx
 
K Nearest neighbour
K Nearest neighbourK Nearest neighbour
K Nearest neighbour
 
Scalable Recommendation Algorithms with LSH
Scalable Recommendation Algorithms with LSHScalable Recommendation Algorithms with LSH
Scalable Recommendation Algorithms with LSH
 
k-NN Algorithm.pptx
k-NN Algorithm.pptxk-NN Algorithm.pptx
k-NN Algorithm.pptx
 
Clustering - ACM 2013 02-25
Clustering - ACM 2013 02-25Clustering - ACM 2013 02-25
Clustering - ACM 2013 02-25
 
knn is the k nearest algorithm ppt that includes all about knn, its adv and d...
knn is the k nearest algorithm ppt that includes all about knn, its adv and d...knn is the k nearest algorithm ppt that includes all about knn, its adv and d...
knn is the k nearest algorithm ppt that includes all about knn, its adv and d...
 
lec02.pptx
lec02.pptxlec02.pptx
lec02.pptx
 
K nearest neighbours
K nearest neighboursK nearest neighbours
K nearest neighbours
 
MrKNN_Soft Relevance for Multi-label Classification
MrKNN_Soft Relevance for Multi-label ClassificationMrKNN_Soft Relevance for Multi-label Classification
MrKNN_Soft Relevance for Multi-label Classification
 
09_dm1_knn_2022_23.pdf
09_dm1_knn_2022_23.pdf09_dm1_knn_2022_23.pdf
09_dm1_knn_2022_23.pdf
 
Instance based learning
Instance based learningInstance based learning
Instance based learning
 

More from Amir Shokri

LAUNCH - growth practices - PRODUCT MANAGER
LAUNCH - growth practices - PRODUCT MANAGERLAUNCH - growth practices - PRODUCT MANAGER
LAUNCH - growth practices - PRODUCT MANAGER
Amir Shokri
 
Remote work
Remote workRemote work
Remote work
Amir Shokri
 
Project Management Growth Practices
Project Management Growth PracticesProject Management Growth Practices
Project Management Growth Practices
Amir Shokri
 
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7
Amir Shokri
 
Numbers, math operation, converting bases
Numbers, math operation, converting basesNumbers, math operation, converting bases
Numbers, math operation, converting bases
Amir Shokri
 
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4
Amir Shokri
 
review of image memorability methods
review of image memorability methodsreview of image memorability methods
review of image memorability methods
Amir Shokri
 
key.net
key.netkey.net
key.net
Amir Shokri
 
beyesian learning exercises
beyesian learning exercisesbeyesian learning exercises
beyesian learning exercises
Amir Shokri
 
Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
Amir Shokri
 
machine learning code
machine learning codemachine learning code
machine learning code
Amir Shokri
 
machine learning - id3, find-s, candidate elimination, desicion tree example
machine learning - id3, find-s, candidate elimination, desicion tree examplemachine learning - id3, find-s, candidate elimination, desicion tree example
machine learning - id3, find-s, candidate elimination, desicion tree example
Amir Shokri
 
ID3 Algorithm
ID3 AlgorithmID3 Algorithm
ID3 Algorithm
Amir Shokri
 
Concept learning
Concept learningConcept learning
Concept learning
Amir Shokri
 
logical operators decision tree
logical operators decision treelogical operators decision tree
logical operators decision tree
Amir Shokri
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
Amir Shokri
 
Mining social network graphs - persian
Mining social network graphs - persianMining social network graphs - persian
Mining social network graphs - persian
Amir Shokri
 
product glossary
product glossaryproduct glossary
product glossary
Amir Shokri
 
Popular Maple codes Book - Persian
Popular Maple codes Book - PersianPopular Maple codes Book - Persian
Popular Maple codes Book - Persian
Amir Shokri
 
deepswarm optimising convolutional neural networks using swarm intelligence (...
deepswarm optimising convolutional neural networks using swarm intelligence (...deepswarm optimising convolutional neural networks using swarm intelligence (...
deepswarm optimising convolutional neural networks using swarm intelligence (...
Amir Shokri
 

More from Amir Shokri (20)

LAUNCH - growth practices - PRODUCT MANAGER
LAUNCH - growth practices - PRODUCT MANAGERLAUNCH - growth practices - PRODUCT MANAGER
LAUNCH - growth practices - PRODUCT MANAGER
 
Remote work
Remote workRemote work
Remote work
 
Project Management Growth Practices
Project Management Growth PracticesProject Management Growth Practices
Project Management Growth Practices
 
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 7
 
Numbers, math operation, converting bases
Numbers, math operation, converting basesNumbers, math operation, converting bases
Numbers, math operation, converting bases
 
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4
GROWTH PRACTICES - Cracking the PM Career - CHAPTER 4
 
review of image memorability methods
review of image memorability methodsreview of image memorability methods
review of image memorability methods
 
key.net
key.netkey.net
key.net
 
beyesian learning exercises
beyesian learning exercisesbeyesian learning exercises
beyesian learning exercises
 
Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
 
machine learning code
machine learning codemachine learning code
machine learning code
 
machine learning - id3, find-s, candidate elimination, desicion tree example
machine learning - id3, find-s, candidate elimination, desicion tree examplemachine learning - id3, find-s, candidate elimination, desicion tree example
machine learning - id3, find-s, candidate elimination, desicion tree example
 
ID3 Algorithm
ID3 AlgorithmID3 Algorithm
ID3 Algorithm
 
Concept learning
Concept learningConcept learning
Concept learning
 
logical operators decision tree
logical operators decision treelogical operators decision tree
logical operators decision tree
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Mining social network graphs - persian
Mining social network graphs - persianMining social network graphs - persian
Mining social network graphs - persian
 
product glossary
product glossaryproduct glossary
product glossary
 
Popular Maple codes Book - Persian
Popular Maple codes Book - PersianPopular Maple codes Book - Persian
Popular Maple codes Book - Persian
 
deepswarm optimising convolutional neural networks using swarm intelligence (...
deepswarm optimising convolutional neural networks using swarm intelligence (...deepswarm optimising convolutional neural networks using swarm intelligence (...
deepswarm optimising convolutional neural networks using swarm intelligence (...
 

Recently uploaded

JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 

Recently uploaded (20)

JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 

Knn

  • 2. KNN Introduction:: K-nearest neighbors is a lazy learning instance based classification algorithm which is widely implemented in both supervised and unsupervised learning techniques. Lazy Learning as it doesn’t learn from discriminative function from training data but memorizes training dataset. this technique implements classification by considering majority of vote among the “k” closest points to the unlabeled data point. It works on unseen data and will search through the training dataset for the k-most similar instances. Euclidean distance / Hamming distance is used as metric for calculating the distance between points. Amir Shokri
  • 3. KNN Euclidean Distance:: 𝒅𝒊𝒔𝒕 𝒙, 𝒚 , 𝒂, 𝒃 = 𝒙 − 𝒂 𝟐 + 𝒚 − 𝒃 𝟐 ) Amir Shokri
  • 4. KNN Hamming Distance:: Onforone oneandone -> 3 11010110110 1100111110 -> 2 Amir Shokri
  • 5. KNN Green circle = ? K = 3 Closest 3 points taken 2 -> orange 1 -> blue 2 orange > 1 blue Green circle is a orange triangle Amir Shokri ? K = 3
  • 6. KNN Green circle = ? K = 5 Closest 5 points taken 2 -> orange 1 -> blue 2 orange < 3 blue Green circle is a blue square Amir Shokri ? K = 5
  • 7. KNN Green circle = ? k = 1 : orange K = 3 : orange K = 5 : orange K = 7 : blue K = 9 : orange Amir Shokri
  • 8. KNN Choosing value of “K” • “k” should be large so that error rate is minimized “k” too small will lead to noisy decision boundaries • “k” should be small enough so that only nearby samples are included “k” too large will lead to over- smoothed boundaries • Setting “k” to the square root of the number of training samples can lead to better results. No Of features = 20 𝑘 = 20 = 4.4 ~ 4 Amir Shokri
  • 9. KNN Amir Shokri 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0 10 20 30 40 50 60 70 80 “k” values vs error curve
  • 10. KNN Amir Shokri 0 10 20 30 40 50 60 0 10 20 30 40 50 60 “k” values vs validation error curve Minimum error Best value of “k”
  • 11. KNN Pros. • Non complex and very easy to understand and implement. • Useful for non linear data as no assumptions about data. • High accuracy (relatively), but no competitive compared to supervised learning algorithms. • Can be used both for classification or regression. • Best used where the probability distribution is unknown. Amir Shokri
  • 12. KNN Cons. • Computationally expensive. • Lot of space is consumed as all the data points are stored. • Sensitive to irrelevant features and the scale of the data. • Output purely depends on k value chosen by user which can reduce accuracy for some values. Amir Shokri
  • 13. KNN Applications. • Recommender systems • Medicine • Finance • Text mining • agriculture Amir Shokri
  • 15. KNN Bias : miss relevant relations within the data; everything gets skewed into specific classes -> underfitting. Variance : too may hypotheses results in hallucination patterns -> overfitting How To verify ? Split data in a test and training set Amir Shokri
  • 16. KNN Bias : miss relevant relations within the data; everything gets skewed into specific classes -> underfitting. Variance : too may hypotheses results in hallucination patterns -> overfitting How To verify ? Split data in a test and training set Amir Shokri
  • 17. KNN Will nearest-neighbours have high bias or high variance ? -> high variance ! • Every instance is an hypothesis : the decision boundary is very/too detailed • How can we solve this? • How to smooth the data obtain a more general model? • K-nearest neighbours (knn) • Weighted average • Prototypes • Locally weighted regresson Amir Shokri
  • 18. KNN • For some value k take the k nearest neighbors of the new instance, and predict the class that is most common among these k neighbors • Alleviates overfitting to a certain degree • Smoother decision boundaries • Influence of outliers is attenuated Amir Shokri
  • 19. KNN • What should k be ? • Too low: overfitting • Too high : underfitting • Strategies: • Cross-validation • Heuristics • algorithms Amir Shokri