SlideShare a Scribd company logo
1 of 16
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 determinationMehediHasan1023
 
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/15MLconf
 
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 CompetitionsBen Hamner
 
Introduction to machine learning algorithms
Introduction to machine learning algorithmsIntroduction to machine learning algorithms
Introduction to machine learning algorithmsbigdata 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 RBarbara 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 distributionUnsa 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 middleschoolaiclub_slides
 
Pa2 project template
Pa2 project templatePa2 project template
Pa2 project templateaiclub_slides
 
M1 regression metrics_middleschool
M1 regression metrics_middleschoolM1 regression metrics_middleschool
M1 regression metrics_middleschoolaiclub_slides
 
Ai in real life face detection
Ai in real life   face detectionAi in real life   face detection
Ai in real life face detectionaiclub_slides
 
Res net high level intro
Res net high level introRes net high level intro
Res net high level introaiclub_slides
 
Neural networks and flattened images
Neural networks and flattened imagesNeural networks and flattened images
Neural networks and flattened imagesaiclub_slides
 
What is a_neural_network
What is a_neural_networkWhat is a_neural_network
What is a_neural_networkaiclub_slides
 
How neural networks learn part iii
How neural networks learn part iiiHow neural networks learn part iii
How neural networks learn part iiiaiclub_slides
 
Introduction to deep learning image classification
Introduction to deep learning   image classificationIntroduction to deep learning   image classification
Introduction to deep learning image classificationaiclub_slides
 
Accuracy middleschool
Accuracy middleschoolAccuracy middleschool
Accuracy middleschoolaiclub_slides
 
Introduction to classification_middleschool
Introduction to classification_middleschoolIntroduction to classification_middleschool
Introduction to classification_middleschoolaiclub_slides
 
Introduction to the cloud
Introduction to the cloudIntroduction to the cloud
Introduction to the cloudaiclub_slides
 
Ai lifecycle and navigator
Ai lifecycle and navigatorAi lifecycle and navigator
Ai lifecycle and navigatoraiclub_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 1aiclub_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

MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

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!