SlideShare a Scribd company logo
1 of 22
Download to read offline
Machine Learning Programming
BDA712-00
Lecturer: Josué Obregón PhD
Kyung Hee University
Department of Big Data Analytics
October 12, 2022
Logistic Regression II:
Model validation, image recognition and multiclass classification
1
Machine Learning Programming, KHU
Your first learning
program
Building a tiny
supervised learning
program
Hyperspace!
Multiple linear
regression
Getting real
Recognize a single digit
using MNSIT
A discerning
machine
From regression to
classification
Walking the
gradient
Gradient descent
algorithm
Previously, in our course…
Your first learning
program
Building a tiny
supervised learning
program
Hyperspace!
Multiple linear
regression
Getting real
Recognize a single digit
using MNSIT
A discerning
machine
From regression to
classification
Walking the
gradient
Gradient descent
algorithm
And today…
Today's agenda
• Model evaluation and selection
• Training vs.Testing
• MINST dataset
• Data input format
• Recognizing a single digit
• Data preprocessing and encoding
• Going multiclass
• Intuition behind the loss function
• Transforming linear regression to logistic regression
Machine Learning Programming, KHU 4
How should we think about model selection?
One of the central themes of this class, and Machine Learning is:
Generalizability: We want to construct models that generalize
well to unseen data
• i.e.,We want to:
1
2
Add variables/flexibility as long as doing so helps capture meaningful
trends in the data (avoid underfitting)
Ignore meaningless random fluctuations in the data (avoid overfitting)
Machine Learning Programming, KHU 5
How should we think about model selection?
Let’s remind ourselves of the first CentralTheme of this class.
1. Generalizability: We want to construct models that generalize
well to unseen data
• i.e.,We want to:
1
2
Add variables/flexibility as long as doing so helps capture meaningful
trends in the data (avoid underfitting)
Ignore meaningless random fluctuations in the day (avoid overfitting)
Machine Learning Programming, KHU 6
Assessing Model Performance
• Suppose we fit a model ̂
𝑓𝑓 𝑥𝑥 to some training data: Train = 𝑥𝑥 𝑖𝑖
, 𝑦𝑦(𝑖𝑖)
𝑖𝑖=1
𝑛𝑛
• We want to assess how well ̂
𝑓𝑓 performs
• We can compute the average squared prediction error over Train
𝑀𝑀𝑀𝑀𝐸𝐸𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 = 1
𝑛𝑛
∑𝑖𝑖=1
𝑛𝑛
𝑦𝑦(𝑖𝑖)− ̂
𝑓𝑓 𝑥𝑥 𝑖𝑖
2
• But this may push us towards more overfit models.
• Instead,we should compute it using fresh test data: Train = 𝑥𝑥 𝑖𝑖
, 𝑦𝑦(𝑖𝑖)
𝑖𝑖=1
𝑚𝑚
𝑀𝑀𝑀𝑀𝐸𝐸𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 = 1
𝑛𝑛
∑𝑖𝑖=1
𝑚𝑚
𝑦𝑦(𝑖𝑖)− ̂
𝑓𝑓 𝑥𝑥 𝑖𝑖
2
• This would tell us if ̂
𝑓𝑓 generalizes well to new data
Machine Learning Programming, KHU 7
Assessing Model Accuracy:Training Error vs.Testing Error
Here are three different models fit to the same small Train data set. Which of these three
is the best model?
Machine Learning Programming, KHU 8
Assessing Model Accuracy:Training Error vs.Testing Error
Model 1 2 3
MSETrain = RSS/n 23.2 5.2 7.5
Machine Learning Programming, KHU 9
Assessing Model Accuracy:Training Error vs.Testing Error
Here are some new observations,which form our Test data. How well do our models fit the
Test data?
Solid green points: Test data Open grey circles: Train data
Machine Learning Programming, KHU 10
Assessing Model Accuracy:Training Error vs.Testing Error
Model 1 2 3
MSETrain 23.2 5.2 7.5
MSETest 24.6 10.3 7.0
Machine Learning Programming, KHU 11
Assessing Model Accuracy
• As we increase the flexibility of our model, our training set error always decreases
• The same is not true for test set error
• The test set error will decrease as we add flexibility that helps to capture useful
trends
• As we add too much flexibility, the test set error will begin to increase
due to model overfitting
Machine Learning Programming, KHU 12
Computer vision tasks
Machine Learning Programming, KHU 13
Image classification
https://medium.com/analytics-vidhya/image-classification-
vs-object-detection-vs-image-segmentation-f36db85fe81
MNIST Data
• MNIST is a collection of labeled images that’s been assembled
specifically for supervised learning.
• Its name stands for “Modified NIST,” because it’s a remix of earlier data from
the National Institute of Standards and Technology.
• MNIST contains images of handwritten digits, labeled with their
numerical values.
• 60,000 images for training and 10,000 for testing
Machine Learning Programming, KHU 14
MNIST Data
• Digits are made up of 28 by 28 grayscale pixels, each represented by
one byte.
• In MNIST’s grayscale, 0 stands for “perfect background white,” and
255 stands for “perfect foreground black.”
Machine Learning Programming, KHU 15
How to interpret image data
Machine Learning Programming, KHU 16
https://dev.to/sandeepbalachandran/machine-
learning-going-furthur-with-cnn-part-2-41km
Preparing the input Matrices
Machine Learning Programming, KHU 17
28×28 image
Flatten or reshape the 2D
matrix into a 1D vector 0 0 0 235 .. .. 1 2 1 0
We will get a 784 sized 1D vector
Add the bias column
Input for our logistic
regression algorithm
Preparing the input Matrices
Machine Learning Programming, KHU 18
Let’s get real (Lab Session 06)
Goal: Build a program on top of our previous implementation to use the
MNIST dataset as input and classify the images according to the digits
from 0 to 9.Additionally, check the generalization capabilities of our
model by checking the performance on unseen data (test set).
Let’s do it!
• https://classroom.github.com/a/R-cw8Rn-
Machine Learning Programming, KHU 19
Going Multiclass
Machine Learning Programming, KHU 20
One-hot encoding
Machine Learning Programming, KHU 21
Acknowledgements
Some of the lectures notes for this class feature content borrowed with
or without modification from the following sources:
• 95-791Data Mining Carneige Mellon University, Lecture notes (Prof.
Alexandra Chouldechova)
• An Introduction to Statistical Learning, with applications in R (Springer, 2013)
with permission from the authors: G. James, D. Witten, T. Hastie and R.
Tibshirani
• Machine learning online course from Andrew Ng
Machine Learning Programming, KHU 22

More Related Content

Similar to Session 6.pdf

Keynote at IWLS 2017
Keynote at IWLS 2017Keynote at IWLS 2017
Keynote at IWLS 2017Manish Pandey
 
Keynote at IWLS 2017
Keynote at IWLS 2017Keynote at IWLS 2017
Keynote at IWLS 2017Manish Pandey
 
House price prediction
House price predictionHouse price prediction
House price predictionSabahBegum
 
House price prediction
House price predictionHouse price prediction
House price predictionSabahBegum
 
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud MLScaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud MLSeldon
 
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud MLScaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud MLSeldon
 
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETSFAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETScsandit
 
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETSFAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETScsandit
 
Jay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIJay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIAI Frontiers
 
Jay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIJay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIAI Frontiers
 
Fast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareFast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareTigerGraph
 
Fast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareFast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareTigerGraph
 
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...Mokhtar SELLAMI
 
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...Mokhtar SELLAMI
 
Machine Learning With ML.NET
Machine Learning With ML.NETMachine Learning With ML.NET
Machine Learning With ML.NETDev Raj Gautam
 
G. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statisticsG. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statisticsIstituto nazionale di statistica
 

Similar to Session 6.pdf (20)

Keynote at IWLS 2017
Keynote at IWLS 2017Keynote at IWLS 2017
Keynote at IWLS 2017
 
Keynote at IWLS 2017
Keynote at IWLS 2017Keynote at IWLS 2017
Keynote at IWLS 2017
 
House price prediction
House price predictionHouse price prediction
House price prediction
 
House price prediction
House price predictionHouse price prediction
House price prediction
 
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud MLScaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
 
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud MLScaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
Scaling TensorFlow Models for Training using multi-GPUs & Google Cloud ML
 
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETSFAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
 
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETSFAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
FAST ALGORITHMS FOR UNSUPERVISED LEARNING IN LARGE DATA SETS
 
Jay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIJay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AI
 
Jay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AIJay Yagnik at AI Frontiers : A History Lesson on AI
Jay Yagnik at AI Frontiers : A History Lesson on AI
 
Big Data Challenges and Solutions
Big Data Challenges and SolutionsBig Data Challenges and Solutions
Big Data Challenges and Solutions
 
Big Data Challenges and Solutions
Big Data Challenges and SolutionsBig Data Challenges and Solutions
Big Data Challenges and Solutions
 
presentationIDC - 14MAY2015
presentationIDC - 14MAY2015presentationIDC - 14MAY2015
presentationIDC - 14MAY2015
 
presentationIDC - 14MAY2015
presentationIDC - 14MAY2015presentationIDC - 14MAY2015
presentationIDC - 14MAY2015
 
Fast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareFast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA Hardware
 
Fast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareFast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA Hardware
 
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
 
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
CARI-2020, Application of LSTM architectures for next frame forecasting in Se...
 
Machine Learning With ML.NET
Machine Learning With ML.NETMachine Learning With ML.NET
Machine Learning With ML.NET
 
G. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statisticsG. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statistics
 

Recently uploaded

Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 

Recently uploaded (20)

Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 

Session 6.pdf

  • 1. Machine Learning Programming BDA712-00 Lecturer: Josué Obregón PhD Kyung Hee University Department of Big Data Analytics October 12, 2022 Logistic Regression II: Model validation, image recognition and multiclass classification 1 Machine Learning Programming, KHU
  • 2. Your first learning program Building a tiny supervised learning program Hyperspace! Multiple linear regression Getting real Recognize a single digit using MNSIT A discerning machine From regression to classification Walking the gradient Gradient descent algorithm Previously, in our course…
  • 3. Your first learning program Building a tiny supervised learning program Hyperspace! Multiple linear regression Getting real Recognize a single digit using MNSIT A discerning machine From regression to classification Walking the gradient Gradient descent algorithm And today…
  • 4. Today's agenda • Model evaluation and selection • Training vs.Testing • MINST dataset • Data input format • Recognizing a single digit • Data preprocessing and encoding • Going multiclass • Intuition behind the loss function • Transforming linear regression to logistic regression Machine Learning Programming, KHU 4
  • 5. How should we think about model selection? One of the central themes of this class, and Machine Learning is: Generalizability: We want to construct models that generalize well to unseen data • i.e.,We want to: 1 2 Add variables/flexibility as long as doing so helps capture meaningful trends in the data (avoid underfitting) Ignore meaningless random fluctuations in the data (avoid overfitting) Machine Learning Programming, KHU 5
  • 6. How should we think about model selection? Let’s remind ourselves of the first CentralTheme of this class. 1. Generalizability: We want to construct models that generalize well to unseen data • i.e.,We want to: 1 2 Add variables/flexibility as long as doing so helps capture meaningful trends in the data (avoid underfitting) Ignore meaningless random fluctuations in the day (avoid overfitting) Machine Learning Programming, KHU 6
  • 7. Assessing Model Performance • Suppose we fit a model ̂ 𝑓𝑓 𝑥𝑥 to some training data: Train = 𝑥𝑥 𝑖𝑖 , 𝑦𝑦(𝑖𝑖) 𝑖𝑖=1 𝑛𝑛 • We want to assess how well ̂ 𝑓𝑓 performs • We can compute the average squared prediction error over Train 𝑀𝑀𝑀𝑀𝐸𝐸𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 = 1 𝑛𝑛 ∑𝑖𝑖=1 𝑛𝑛 𝑦𝑦(𝑖𝑖)− ̂ 𝑓𝑓 𝑥𝑥 𝑖𝑖 2 • But this may push us towards more overfit models. • Instead,we should compute it using fresh test data: Train = 𝑥𝑥 𝑖𝑖 , 𝑦𝑦(𝑖𝑖) 𝑖𝑖=1 𝑚𝑚 𝑀𝑀𝑀𝑀𝐸𝐸𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 = 1 𝑛𝑛 ∑𝑖𝑖=1 𝑚𝑚 𝑦𝑦(𝑖𝑖)− ̂ 𝑓𝑓 𝑥𝑥 𝑖𝑖 2 • This would tell us if ̂ 𝑓𝑓 generalizes well to new data Machine Learning Programming, KHU 7
  • 8. Assessing Model Accuracy:Training Error vs.Testing Error Here are three different models fit to the same small Train data set. Which of these three is the best model? Machine Learning Programming, KHU 8
  • 9. Assessing Model Accuracy:Training Error vs.Testing Error Model 1 2 3 MSETrain = RSS/n 23.2 5.2 7.5 Machine Learning Programming, KHU 9
  • 10. Assessing Model Accuracy:Training Error vs.Testing Error Here are some new observations,which form our Test data. How well do our models fit the Test data? Solid green points: Test data Open grey circles: Train data Machine Learning Programming, KHU 10
  • 11. Assessing Model Accuracy:Training Error vs.Testing Error Model 1 2 3 MSETrain 23.2 5.2 7.5 MSETest 24.6 10.3 7.0 Machine Learning Programming, KHU 11
  • 12. Assessing Model Accuracy • As we increase the flexibility of our model, our training set error always decreases • The same is not true for test set error • The test set error will decrease as we add flexibility that helps to capture useful trends • As we add too much flexibility, the test set error will begin to increase due to model overfitting Machine Learning Programming, KHU 12
  • 13. Computer vision tasks Machine Learning Programming, KHU 13 Image classification https://medium.com/analytics-vidhya/image-classification- vs-object-detection-vs-image-segmentation-f36db85fe81
  • 14. MNIST Data • MNIST is a collection of labeled images that’s been assembled specifically for supervised learning. • Its name stands for “Modified NIST,” because it’s a remix of earlier data from the National Institute of Standards and Technology. • MNIST contains images of handwritten digits, labeled with their numerical values. • 60,000 images for training and 10,000 for testing Machine Learning Programming, KHU 14
  • 15. MNIST Data • Digits are made up of 28 by 28 grayscale pixels, each represented by one byte. • In MNIST’s grayscale, 0 stands for “perfect background white,” and 255 stands for “perfect foreground black.” Machine Learning Programming, KHU 15
  • 16. How to interpret image data Machine Learning Programming, KHU 16 https://dev.to/sandeepbalachandran/machine- learning-going-furthur-with-cnn-part-2-41km
  • 17. Preparing the input Matrices Machine Learning Programming, KHU 17 28×28 image Flatten or reshape the 2D matrix into a 1D vector 0 0 0 235 .. .. 1 2 1 0 We will get a 784 sized 1D vector Add the bias column Input for our logistic regression algorithm
  • 18. Preparing the input Matrices Machine Learning Programming, KHU 18
  • 19. Let’s get real (Lab Session 06) Goal: Build a program on top of our previous implementation to use the MNIST dataset as input and classify the images according to the digits from 0 to 9.Additionally, check the generalization capabilities of our model by checking the performance on unseen data (test set). Let’s do it! • https://classroom.github.com/a/R-cw8Rn- Machine Learning Programming, KHU 19
  • 20. Going Multiclass Machine Learning Programming, KHU 20
  • 21. One-hot encoding Machine Learning Programming, KHU 21
  • 22. Acknowledgements Some of the lectures notes for this class feature content borrowed with or without modification from the following sources: • 95-791Data Mining Carneige Mellon University, Lecture notes (Prof. Alexandra Chouldechova) • An Introduction to Statistical Learning, with applications in R (Springer, 2013) with permission from the authors: G. James, D. Witten, T. Hastie and R. Tibshirani • Machine learning online course from Andrew Ng Machine Learning Programming, KHU 22