SlideShare a Scribd company logo
1 of 38
Download to read offline
14 Classification
Prof. Dr. Ziawasch Abedjan, Felix Neutatz
June 24th
2019
Repetition: Prediction
How old is this dugong?
2
Years
0 73
Dugong by Geoff Spiby is licensed under CC BY-SA 3.0
Classification
https://www.inferentialthinking.com/chapters/17/Classification.html
Is this Classification?
● Is this bank transfer fraudulent?
● Is this patient healthy?
● Will you vote for me, for X, or for Y?
● Will these two people fit to each other?
● Is this an apple?
Def.: Given a number of examples, identify to which class a given
observation belongs to.
4
What do we need for apple classification?
Mass Width Height Is an Apple
192 8.4 7.3 1
342 9 9.4 0
186 7.2 9.2 0
152 7.6 7.3 1
Observations
Attributes Class
80 5.9 4.3 1
194 7.2 10.3 0
Training data
Test data
https://homepages.inf.ed.ac.uk/imurray2/teaching/oranges_and_lemons/
5
Nearest Neighbors
https://www.inferentialthinking.com/chapters/17/1/Nearest_Neighbors.html
Classification based on Height and Width
7
Classification based on Height and Width
8
A Nearest Neighbor Classifier
● Find the point in the training set that is nearest to the new point.
● If that nearest point is an apple, classify the new point as apple.
9
Decision Boundary
10
Decision Boundary
11
Chronic Kidney Disease Classification
Due to different value ranges, a difference
for the white blood cell count is significantly
more impactful than for Glucose.
⇒ Standard Units
Kidney Cross Section by Anmats is licensed
under CC BY 3.0
12
Glucose White Blood Cell Count Class
117 6700 1
70 12100 1
114 7200 0
131 6800 0
Standard Units
Absolute Distance Standardized Distance
13
What if there is no clear decision boundary?
Does this patient have the chronic kidney disease?
14
K-Nearest Neighbors ill
healthy
● Find the k points in the training set that are nearest to the new point.
● If most nearest points are healthy, classify the new point as healthy.
15
Which K?
Good fitOverfitting
1-Nearest Neighbors 4-Nearest Neighbors
Underfitting
30-Nearest Neighbors
16
Implementing the Classifier
https://www.inferentialthinking.com/chapters/17/4/Implementing_the_Classifier.html
Is Alice ill?
● Step 1: Find the distance between Alice and each point in the training
sample.
● Step 2: Sort the data table in increasing order of the distances.
● Step 3: Take the top k=4 rows of the sorted table.
● Step 4: Choose the majority class of these 4 rows.
18
Is Alice ill?
Step 0.1: Load training data.
Step 0.2: Select and standardize the attributes that we use for classification.
19
Euclidean distance
20
Distance by Jim.belk is licensed under public domain
Applying a function to each row in a table
● We already can apply a function to each element in a column:
TableName.apply(FunctionName, 'ColumnName')
● Now, we want to apply a function to the entire row:
TableName.apply(FunctionName)
21
Is Alice ill?
● Step 1: Find the distance between Alice and each point in the training
sample.
22
Is Alice ill?
● Step 1: Find the distance between Alice and each point in the training
sample.
23
Glucose White Blood Cell Count Class Distance from Alice
-0.2215 -0.569768 1 0.88943
-0.9475 1.16268 1 2.16332
3.8412 -1.27558 1 4.84907
0.3963 0.809777 1 2.28585
0.6435 0.232293 1 2.0542
-0.5614 -0.505603 1 0.660906
Is Alice ill?
● Step 2: Sort the data table in increasing order of the distances.
24
Glucose White Blood Cell Count Class Distance from Alice
-0.94759 -0.98684 0 0.0540298
-0.82401 -0.98684 0 0.176477
-0.87035 -0.794345 0 0.243107
-0.71588 -0.85851 0 0.317401
-0.70043 -0.85851 0 0.331301
Is Alice ill?
● Step 3: Take the top k=4 rows of the sorted table.
25
Glucose White Blood Cell Count Class Distance from Alice
-0.94759 -0.98684 0 0.0540298
-0.82401 -0.98684 0 0.176477
-0.87035 -0.794345 0 0.243107
-0.71588 -0.85851 0 0.317401
Is Alice ill?
● Step 4: Choose the majority class of these 5 rows.
26
All in one:
27
Training and Testing
https://www.inferentialthinking.com/chapters/17/2/Training_and_Testing.html
Training and Testing
● How good is the classifier?
● How well does the classifier predict data that it has not seen before?
29
Training by Luca_Episcopo is licensed under Pixabay
License
Game by pixabay.com is licensed under CC0 1.0
Generating test data (hold-out set)
● We can gather more data,
● or we randomly split the given data into two parts: training and testing.
30
Never test on training data!
Is Felix a good soccer player?
Felix scores 10 goals in the training session with his friends!
So, Felix is a good player!?
Well, in the game, Felix is super nervous and scores own goal.
31
Never train on test data!
If we train a 1-Nearest Neighbor classifier on the following data, would it make any
mistakes on the same data?
32
The Accuracy of the Classifier
https://www.inferentialthinking.com/chapters/17/5/Accuracy_of_the_Classifier.html
Naming Convention for Prediction Evaluation
Was the prediction correct? Which class did we predict?
True False Positive Negative
Example: Prediction = Apple, Ground Truth = Not Apple
⇒ False Positive
34
Accuracy
Ground Truth
Positive Negative
Prediction
Positive True Positive False Positive
Negative False Negative True Negative
35
Accuracy
36
Which K?
Test Accuracy: 0.70Test Accuracy: 0.91Test Accuracy: 0.89
1-Nearest Neighbors 4-Nearest Neighbors 30-Nearest Neighbors
37
Summary
38
● Classification: Given a number of examples, identify to which class a given
observation belongs to.
● We can use the nearest neighbors of an observation to classify it.
● To evaluate a classification model, we split the data into training and test.
● To measure the success, we can use metrics, such as accuracy.

More Related Content

Similar to Lecture on Classification

Singapore presentation copy
Singapore presentation   copySingapore presentation   copy
Singapore presentation copy
lorawallenstein
 
Chapter NineShow all workProblem 1)A skept.docx
Chapter NineShow all workProblem 1)A skept.docxChapter NineShow all workProblem 1)A skept.docx
Chapter NineShow all workProblem 1)A skept.docx
needhamserena
 
Crest awards project_Bee-o-diversity
Crest awards project_Bee-o-diversityCrest awards project_Bee-o-diversity
Crest awards project_Bee-o-diversity
Daniel Tagg
 
Problem solving content
Problem solving contentProblem solving content
Problem solving content
Timothy Welsh
 
problem_solving in physics
 problem_solving in physics problem_solving in physics
problem_solving in physics
Timothy Welsh
 
Caveon webinar series Standard Setting for the 21st Century, Using Informa...
Caveon webinar series    Standard Setting for the 21st Century, Using Informa...Caveon webinar series    Standard Setting for the 21st Century, Using Informa...
Caveon webinar series Standard Setting for the 21st Century, Using Informa...
Caveon Test Security
 

Similar to Lecture on Classification (20)

[ESWC2017 - PhD Symposium] Enhancing white-box machine learning processes by ...
[ESWC2017 - PhD Symposium] Enhancing white-box machine learning processes by ...[ESWC2017 - PhD Symposium] Enhancing white-box machine learning processes by ...
[ESWC2017 - PhD Symposium] Enhancing white-box machine learning processes by ...
 
Singapore presentation copy
Singapore presentation   copySingapore presentation   copy
Singapore presentation copy
 
Chapter NineShow all workProblem 1)A skept.docx
Chapter NineShow all workProblem 1)A skept.docxChapter NineShow all workProblem 1)A skept.docx
Chapter NineShow all workProblem 1)A skept.docx
 
Crest awards project_Bee-o-diversity
Crest awards project_Bee-o-diversityCrest awards project_Bee-o-diversity
Crest awards project_Bee-o-diversity
 
Share shark
Share sharkShare shark
Share shark
 
The College Classroom (Fa14) Week 2: Developing Expertise through Deliberate ...
The College Classroom (Fa14) Week 2: Developing Expertise through Deliberate ...The College Classroom (Fa14) Week 2: Developing Expertise through Deliberate ...
The College Classroom (Fa14) Week 2: Developing Expertise through Deliberate ...
 
Problem solving content
Problem solving contentProblem solving content
Problem solving content
 
problem_solving in physics
 problem_solving in physics problem_solving in physics
problem_solving in physics
 
Central tendency spread
Central tendency spreadCentral tendency spread
Central tendency spread
 
tutor2u Strong Foundations A Level Psychology
tutor2u Strong Foundations A Level Psychologytutor2u Strong Foundations A Level Psychology
tutor2u Strong Foundations A Level Psychology
 
Sciences Games #Glass2015
Sciences Games #Glass2015Sciences Games #Glass2015
Sciences Games #Glass2015
 
ML_1.pdf
ML_1.pdfML_1.pdf
ML_1.pdf
 
Grouping and Displaying Data to Convey Meaning: Tables & Graphs chapter_2 _fr...
Grouping and Displaying Data to Convey Meaning: Tables & Graphs chapter_2 _fr...Grouping and Displaying Data to Convey Meaning: Tables & Graphs chapter_2 _fr...
Grouping and Displaying Data to Convey Meaning: Tables & Graphs chapter_2 _fr...
 
Caveon webinar series Standard Setting for the 21st Century, Using Informa...
Caveon webinar series    Standard Setting for the 21st Century, Using Informa...Caveon webinar series    Standard Setting for the 21st Century, Using Informa...
Caveon webinar series Standard Setting for the 21st Century, Using Informa...
 
CHI (Computer Human Interaction) 2019 enhancing online problems through instr...
CHI (Computer Human Interaction) 2019 enhancing online problems through instr...CHI (Computer Human Interaction) 2019 enhancing online problems through instr...
CHI (Computer Human Interaction) 2019 enhancing online problems through instr...
 
Web People Search
Web People SearchWeb People Search
Web People Search
 
Machine Learning in Unity - How to give your game AI a real brain
Machine Learning in Unity - How to give your game AI a real brainMachine Learning in Unity - How to give your game AI a real brain
Machine Learning in Unity - How to give your game AI a real brain
 
Give your learners the extra cognitive boost - box them
Give your learners the extra cognitive boost  - box themGive your learners the extra cognitive boost  - box them
Give your learners the extra cognitive boost - box them
 
21CLHK9 - Building Heroes
21CLHK9 - Building Heroes21CLHK9 - Building Heroes
21CLHK9 - Building Heroes
 
module_1_ppt.pdf
module_1_ppt.pdfmodule_1_ppt.pdf
module_1_ppt.pdf
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
SaadHumayun7
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 

Lecture on Classification