SlideShare a Scribd company logo
AI Club
AI Club
KNN
K-Nearest Neighbours Algorithm
Classification Dataset
Years in
school
height label
0 2.18 child
7 5.58 adult
4 5.95 adult
4 4.36 child
2 5.53 adult
9 5.38 child
11 5.29 adult
4 5.91 adult
0 3.96 child
1 2.72 child
Adult
Child
Classification Dataset
Years in
school
height label
0 2.18 child
7 5.58 adult
4 5.95 adult
4 4.36 child
2 5.53 adult
9 5.38 child
11 5.29 adult
4 5.91 adult
0 3.96 child
1 2.72 child
0 12
7
6
3
Years in school
Height
(ft)
Adult
Child
Classification Dataset
Years in
school
height label
0 2.18 child
7 5.58 adult
4 5.95 adult
4 4.36 child
2 5.53 adult
9 5.38 child
11 5.29 adult
4 5.91 adult
0 3.96 child
1 2.72 child
0 12
7
6
3
Years in school
Height
(ft)
Adult
Child
Input to AI
Years in school = 6
Height = 5ft
Classification Dataset
Years in
school
height label
0 2.18 child
7 5.58 adult
4 5.95 adult
4 4.36 child
2 5.53 adult
9 5.38 child
11 5.29 adult
4 5.91 adult
0 3.96 child
1 2.72 child
0 12
7
6
3
Years in school
Height
(ft)
If K = 1
Adult
Child
Classification Dataset
Years in
school
height label
0 2.18 child
7 5.58 adult
4 5.95 adult
4 4.36 child
2 5.53 adult
9 5.38 child
11 5.29 adult
4 5.91 adult
0 3.96 child
1 2.72 child
0 12
7
6
3
Years in school
Height
(ft)
If K = 3
Adult
Child
Regression Dataset
index sq_ft age price
1 895 26 707158
2 827 61 285327
3 873 58 365744
4 847 58 338163
5 801 66 204300
6 522 58 14117
7 784 46 388363
8 450 25 121220
9 657 33 381713
10 425 52 82357
0
70
450
30
Sq_ft
age
900
1
3
2
4
5
6
7
8
9
10
Regression Dataset
index sq_ft age price
1 895 26 707158
2 827 61 285327
3 873 58 365744
4 847 58 338163
5 801 66 204300
6 522 58 14117
7 784 46 388363
8 450 25 121220
9 657 33 381713
10 425 52 82357
0
70
450
30
Sq_ft
age
900
1
3
2
4
5
6
7
8
9
10
If K = 3
How do you find the best K?
• The process of find the best hyper-parameters
for a algorithm is called hyper-parameter
tuning.
• In case of KNN, we tune a single parameter
called K.
What is a good price for
House 1?
(a)10,000 (b) 5,000?
House
Number
Square feet age Price
1 1000 0
2 800 0 10,000$
3 1000 100 5,000$
What do you think KNN will do if K=1?
Who is the nearest neighbor of the first
house?
House
Number
Square feet age Price
1 1000 0
2 800 0 10,000$
3 1000 100 5,000$
Square feet age Price
1000 0
800 0 10,000$
1000 100 5,000$
Distance(House 1, House 2) = 200
Distance(House 1, House 3) = 100
Drawbacks of KNN
• Scaling: Different features may have different
ranges in numbers
Lets try it!
• Build an AI to predict
house prices
• Change K and see
how the AI behaves!
THANK YOU
https://aiclub.world
info@pyxeda.ai

More Related Content

Similar to Knn intro advanced_middleschool

Lesson 6 coefficient of determination
Lesson 6   coefficient of determinationLesson 6   coefficient of determination
Lesson 6 coefficient of determination
MehediHasan1023
 
MATH 4-Q2-WEEK9.pptx
MATH 4-Q2-WEEK9.pptxMATH 4-Q2-WEEK9.pptx
MATH 4-Q2-WEEK9.pptx
JOHNRUBIEINSIGNE1
 
Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15
Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15
Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15
MLconf
 
Lessons Learned from Running Hundreds of Kaggle Competitions
Lessons Learned from Running Hundreds of Kaggle CompetitionsLessons Learned from Running Hundreds of Kaggle Competitions
Lessons Learned from Running Hundreds of Kaggle Competitions
Ben Hamner
 
K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)
Abdullah al Mamun
 
Introduction to machine learning algorithms
Introduction to machine learning algorithmsIntroduction to machine learning algorithms
Introduction to machine learning algorithms
bigdata trunk
 
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
 
Clean, Learn and Visualise data with R
Clean, Learn and Visualise data with RClean, Learn and Visualise data with R
Clean, Learn and Visualise data with R
Barbara Fusinska
 
Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...
Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...
Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...
REYBETH RACELIS
 
frequency distribution
 frequency distribution frequency distribution
frequency distribution
Unsa Shakir
 
Kungfu math p3 slide3 (subtraction)
Kungfu math p3 slide3 (subtraction)Kungfu math p3 slide3 (subtraction)
Kungfu math p3 slide3 (subtraction)kungfumath
 

Similar to Knn intro advanced_middleschool (11)

Lesson 6 coefficient of determination
Lesson 6   coefficient of determinationLesson 6   coefficient of determination
Lesson 6 coefficient of determination
 
MATH 4-Q2-WEEK9.pptx
MATH 4-Q2-WEEK9.pptxMATH 4-Q2-WEEK9.pptx
MATH 4-Q2-WEEK9.pptx
 
Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15
Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15
Ben Hamner, Co-founder and CTO, Kaggle at MLconf SF - 11/13/15
 
Lessons Learned from Running Hundreds of Kaggle Competitions
Lessons Learned from Running Hundreds of Kaggle CompetitionsLessons Learned from Running Hundreds of Kaggle Competitions
Lessons Learned from Running Hundreds of Kaggle Competitions
 
K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)K-Nearest Neighbor(KNN)
K-Nearest Neighbor(KNN)
 
Introduction to machine learning algorithms
Introduction to machine learning algorithmsIntroduction to machine learning algorithms
Introduction to machine learning algorithms
 
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...
 
Clean, Learn and Visualise data with R
Clean, Learn and Visualise data with RClean, Learn and Visualise data with R
Clean, Learn and Visualise data with R
 
Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...
Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...
Whole Numbers, Fractions, Decimals, Ratios & Percents, Statistics, Real Numbe...
 
frequency distribution
 frequency distribution frequency distribution
frequency distribution
 
Kungfu math p3 slide3 (subtraction)
Kungfu math p3 slide3 (subtraction)Kungfu math p3 slide3 (subtraction)
Kungfu math p3 slide3 (subtraction)
 

More from aiclub_slides

Linear regression middleschool
Linear regression middleschoolLinear regression middleschool
Linear regression middleschool
aiclub_slides
 
Pa2 project template
Pa2 project templatePa2 project template
Pa2 project template
aiclub_slides
 
M1 regression metrics_middleschool
M1 regression metrics_middleschoolM1 regression metrics_middleschool
M1 regression metrics_middleschool
aiclub_slides
 
Pa1 json requests
Pa1 json requestsPa1 json requests
Pa1 json requests
aiclub_slides
 
Mnist images
Mnist imagesMnist images
Mnist images
aiclub_slides
 
Mnist images
Mnist imagesMnist images
Mnist images
aiclub_slides
 
Ai in real life face detection
Ai in real life   face detectionAi in real life   face detection
Ai in real life face detection
aiclub_slides
 
Res net high level intro
Res net high level introRes net high level intro
Res net high level intro
aiclub_slides
 
Neural networks and flattened images
Neural networks and flattened imagesNeural networks and flattened images
Neural networks and flattened images
aiclub_slides
 
What is a_neural_network
What is a_neural_networkWhat is a_neural_network
What is a_neural_network
aiclub_slides
 
How neural networks learn part iii
How neural networks learn part iiiHow neural networks learn part iii
How neural networks learn part iii
aiclub_slides
 
Introduction to deep learning image classification
Introduction to deep learning   image classificationIntroduction to deep learning   image classification
Introduction to deep learning image classification
aiclub_slides
 
Accuracy middleschool
Accuracy middleschoolAccuracy middleschool
Accuracy middleschool
aiclub_slides
 
Introduction to classification_middleschool
Introduction to classification_middleschoolIntroduction to classification_middleschool
Introduction to classification_middleschool
aiclub_slides
 
Introduction to the cloud
Introduction to the cloudIntroduction to the cloud
Introduction to the cloud
aiclub_slides
 
Basics of data
Basics of dataBasics of data
Basics of data
aiclub_slides
 
Ai basics
Ai basicsAi basics
Ai basics
aiclub_slides
 
Ai lifecycle and navigator
Ai lifecycle and navigatorAi lifecycle and navigator
Ai lifecycle and navigator
aiclub_slides
 
How AIs are different from us level 1
How AIs are different from us   level 1How AIs are different from us   level 1
How AIs are different from us level 1
aiclub_slides
 

More from aiclub_slides (20)

Linear regression middleschool
Linear regression middleschoolLinear regression middleschool
Linear regression middleschool
 
Pa2 project template
Pa2 project templatePa2 project template
Pa2 project template
 
M1 regression metrics_middleschool
M1 regression metrics_middleschoolM1 regression metrics_middleschool
M1 regression metrics_middleschool
 
Pa1 json requests
Pa1 json requestsPa1 json requests
Pa1 json requests
 
Mnist images
Mnist imagesMnist images
Mnist images
 
Mnist images
Mnist imagesMnist images
Mnist images
 
Ai in real life face detection
Ai in real life   face detectionAi in real life   face detection
Ai in real life face detection
 
Cnn
CnnCnn
Cnn
 
Res net high level intro
Res net high level introRes net high level intro
Res net high level intro
 
Neural networks and flattened images
Neural networks and flattened imagesNeural networks and flattened images
Neural networks and flattened images
 
What is a_neural_network
What is a_neural_networkWhat is a_neural_network
What is a_neural_network
 
How neural networks learn part iii
How neural networks learn part iiiHow neural networks learn part iii
How neural networks learn part iii
 
Introduction to deep learning image classification
Introduction to deep learning   image classificationIntroduction to deep learning   image classification
Introduction to deep learning image classification
 
Accuracy middleschool
Accuracy middleschoolAccuracy middleschool
Accuracy middleschool
 
Introduction to classification_middleschool
Introduction to classification_middleschoolIntroduction to classification_middleschool
Introduction to classification_middleschool
 
Introduction to the cloud
Introduction to the cloudIntroduction to the cloud
Introduction to the cloud
 
Basics of data
Basics of dataBasics of data
Basics of data
 
Ai basics
Ai basicsAi basics
Ai basics
 
Ai lifecycle and navigator
Ai lifecycle and navigatorAi lifecycle and navigator
Ai lifecycle and navigator
 
How AIs are different from us level 1
How AIs are different from us   level 1How AIs are different from us   level 1
How AIs are different from us level 1
 

Recently uploaded

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
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
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
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
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
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)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
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
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
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
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 

Knn intro advanced_middleschool

  • 3. Classification Dataset Years in school height label 0 2.18 child 7 5.58 adult 4 5.95 adult 4 4.36 child 2 5.53 adult 9 5.38 child 11 5.29 adult 4 5.91 adult 0 3.96 child 1 2.72 child Adult Child
  • 4. Classification Dataset Years in school height label 0 2.18 child 7 5.58 adult 4 5.95 adult 4 4.36 child 2 5.53 adult 9 5.38 child 11 5.29 adult 4 5.91 adult 0 3.96 child 1 2.72 child 0 12 7 6 3 Years in school Height (ft) Adult Child
  • 5. Classification Dataset Years in school height label 0 2.18 child 7 5.58 adult 4 5.95 adult 4 4.36 child 2 5.53 adult 9 5.38 child 11 5.29 adult 4 5.91 adult 0 3.96 child 1 2.72 child 0 12 7 6 3 Years in school Height (ft) Adult Child Input to AI Years in school = 6 Height = 5ft
  • 6. Classification Dataset Years in school height label 0 2.18 child 7 5.58 adult 4 5.95 adult 4 4.36 child 2 5.53 adult 9 5.38 child 11 5.29 adult 4 5.91 adult 0 3.96 child 1 2.72 child 0 12 7 6 3 Years in school Height (ft) If K = 1 Adult Child
  • 7. Classification Dataset Years in school height label 0 2.18 child 7 5.58 adult 4 5.95 adult 4 4.36 child 2 5.53 adult 9 5.38 child 11 5.29 adult 4 5.91 adult 0 3.96 child 1 2.72 child 0 12 7 6 3 Years in school Height (ft) If K = 3 Adult Child
  • 8. Regression Dataset index sq_ft age price 1 895 26 707158 2 827 61 285327 3 873 58 365744 4 847 58 338163 5 801 66 204300 6 522 58 14117 7 784 46 388363 8 450 25 121220 9 657 33 381713 10 425 52 82357 0 70 450 30 Sq_ft age 900 1 3 2 4 5 6 7 8 9 10
  • 9. Regression Dataset index sq_ft age price 1 895 26 707158 2 827 61 285327 3 873 58 365744 4 847 58 338163 5 801 66 204300 6 522 58 14117 7 784 46 388363 8 450 25 121220 9 657 33 381713 10 425 52 82357 0 70 450 30 Sq_ft age 900 1 3 2 4 5 6 7 8 9 10 If K = 3
  • 10. How do you find the best K? • The process of find the best hyper-parameters for a algorithm is called hyper-parameter tuning. • In case of KNN, we tune a single parameter called K.
  • 11. What is a good price for House 1? (a)10,000 (b) 5,000? House Number Square feet age Price 1 1000 0 2 800 0 10,000$ 3 1000 100 5,000$
  • 12. What do you think KNN will do if K=1? Who is the nearest neighbor of the first house? House Number Square feet age Price 1 1000 0 2 800 0 10,000$ 3 1000 100 5,000$
  • 13. Square feet age Price 1000 0 800 0 10,000$ 1000 100 5,000$ Distance(House 1, House 2) = 200 Distance(House 1, House 3) = 100
  • 14. Drawbacks of KNN • Scaling: Different features may have different ranges in numbers
  • 15. Lets try it! • Build an AI to predict house prices • Change K and see how the AI behaves!