SlideShare a Scribd company logo
1 of 28
Download to read offline
Lecturer: Jie Cai, jiec@iti.sdu.dk
OM-DSML
Session 10:
Support Vector Machines
2
To understand & learn the basic concepts of
maximal margin classifier, support vector
classifier, support vector machines and their
application in sciki-learn by examples.
Course Objective
James et al, Chapter 9: Support vector machines, P 367-386
Agenda of Session 10
โ‘ Maximal margin classifier
โ–ช Definition of hyperplane, classifier margin and support vectors.
โ–ช Basics of the optimization function in linear domain
โ‘ Support vector classifier
โ–ช Basics and definition related to support vector classifier accounting for outliers
โ–ช Python code
โ‘ Support vector machines
โ–ช Introduction of SVM in non-linear domain
โ–ช The concept of kernels
โ–ช Python code
โ‘ Multi-class classification
โ–ช Two approaches to apply SVM
โ–ช Python code
โ‘ Support vector regression
โ–ช Introduction to the concept and code application.
3
Support vector machines
โ‘ What is support vector machines (SVM)
โ–ช One of the most powerful โ€œblack boxโ€ learning algorithms in ML field
โ–ช One of the most widely used ML methods nowadays
โ–ช It loosely refers to the maximal margin classifier, the support vector classifier, and
the support vector machine
โ–ช Maximal margin classifier
-Use a hyperplane with a maximal margin to sperate a binary classification
problem.
โ–ช Support vector classifier (soft margin classifier)
-An extension of the maximal margin classifier that can be applied in a broader
range of cases, where misclassified samples are allowed.
โ–ช Support vector machine
-A further extension of the support vector classifier in order to accommodate non-
linear class boundaries.
4
Support vector machines
โ‘ Maximal margin classifier
โ–ช What is the hyperplane ?
-In a p-dimensional space, a hyperplane is a flat affine subspace of dimension p โˆ’ 1.
-E.g., in a 2D space, a hyperplane is
defined by the mathematical equation:
5
Figure 9.1. The hyperplane 1+2X1 + 3X2 = 0 is shown.
Support vector machines
โ‘ Maximal margin classifier
- How would you separate these two groups of training examples with
a straight line ?
Suppose:
Training data: X โˆˆ (n,2), เทก
๐’€ โˆˆ(n,1)
6
A sample binary classification problem with two features
๐œท๐ŸŽ + ๐œท๐Ÿ ๐’™๐Ÿ + ๐œท๐Ÿ ๐’™๐Ÿ =0
Support vector machines
โ‘ Maximal margin classifier
- How would you separate these two groups of training examples with
a straight line ?
We need to train a model:
Find a hyperplane, all samples should be satisfied :
if defined class value as โ†’ y (๐œท๐ŸŽ + ๐œท๐Ÿ ๐’™๐Ÿ + ๐œท๐Ÿ ๐’™๐Ÿ) >0
แ‰ˆ
๐Ÿ
โˆ’๐Ÿ
Support vector machines
โ‘ Maximal margin classifier
โ–ช Margin
- Means the plane we found should be
the farthest to the nearest samples;
- Defined as the width the decision
boundary area can be increased
before hitting a sample data point.
8
A sample binary classification problem with two features
Margin
๐’…๐’Š๐’”๐’• =
๐œท๐ŸŽ + ๐œท๐Ÿ ๐’™๐’Š๐Ÿ + โ‹ฏ + ๐œท๐’‘ ๐’™๐’Š๐’‘
๐œท๐’‹
๐Ÿ
Support vector machines
โ‘ Maximal margin classifier
โ–ช Support vectors
- Defined as the samples determining
such a hyperplane;
- The maximal margin hyperplane
depends directly on only a small
subset of the observations
Therefore, the linear classifier with the
maximum margin is also called a linear
support vector machine (LSVM)
9
A sample binary classification problem with two features
Margin
Support vector machines
โ‘ Construction of the Maximal Margin Classifier
The optimization problem:
The problem:
โ–ช No such linear hyperplanes exit for many cases.
โ–ช A soft-margin is needed, allowing outliers.
10
Support vector machines
โ‘ Maximal margin Classifiers
โ–ช Maximal margin classifier is sensitive to individual samples
โ–ช Not robust
โ–ช Overfitting
Therefore, rather than seeking the largest possible margin so that every observation is not only on the
correct side of the hyperplane but also on the correct side of the margin, we instead allow some
observations to be on the incorrect side of the margin, or even the incorrect side of the hyperplane.
11
Support vector machines
โ‘ Support Vector Classifiers
โ–ช Soft margin classifier
- The margin is soft because it can be violated by some of the training
observations.
12
๐๐’Š = แ‰
๐ŸŽ: ๐‘ด๐‘ด๐‘ช
> ๐ŸŽ โˆถ ๐’—๐’Š๐’๐’๐’…๐’‚๐’•๐’†๐’… ๐’Ž๐’‚๐’“๐’ˆ๐’Š๐’
> ๐Ÿ โˆถ ๐’˜๐’“๐’๐’๐’ˆ ๐’”๐’Š๐’…๐’† ๐’๐’‡ ๐’‰๐’š๐’‘๐’†๐’“๐’‘๐’๐’‚๐’
Slack variable
Tuning parameter
Small C: small margin, less tolerance, low bias but high variance
Large C: large margin, large tolerance, high bias but low variance
Support vector machines
โ‘ Support Vector classifier-linear
โ–ช Pros:
โ–ช Simple and easy to train
โ–ช Fast prediction
โ–ช Reasons for prediction are relatively easy to interpret
โ–ช Cons:
โ–ช For lower-dimensional data, other models may have superior
generalization performance
โ–ช For classification, data may not be linearly separable (we will talk about
more in the next part for non-linear kernels).
13
Agenda of Session 10
โ‘ Maximal margin classifier
โ–ช Definition of hyperplane, classifier margin and support vectors.
โ–ช Basics to the optimization function in linear domain
โ‘ Support vector classifier
โ–ช Basics and definition related to support vector classifier accounting for outliers
โ–ช Python code application
โ‘ Support vector machines
โ–ช Introduction of SVM in non-linear domain
โ–ช The concept of kernels
โ–ช Python code
โ‘ Multi-class classification
โ–ช Two approaches to apply SVM
โ–ช Python code application
โ‘ Support vector regression
โ–ช Introduction to the concept and code application.
14
Support vector machines
โ‘ Support Vector machines
There is still one problem we can not figure out , binary classification with a non-
linear boundary.
15
Linear boundary
Non-linear boundary
Therefore, enlarge the feature space
E.g., 2Dโ†’ 3D problem.
Or using quadratic, cubic, and even
higher-order polynomial functions of
the predictors
Support vector machines
โ‘ Support Vector machines
16
An example of mapping a 2D classification problem to a 3D feature
space to make it linear separable
Support vector machines
โ‘ Support Vector machines
17
An example of mapping a 2D classification problem to a 3D feature
space to make it linear separable
Support vector machines
โ‘ Support Vector Machines
- The SVM is an extension of the support vector classifier that results from
enlarging the feature space in a specific way, using kernels.
โ–ช Kernels
- The function that quantifies the similarity of two observations.
E.g., for the linear support classifier,
18
similarity (xi, xiยด)=exp(-g xi โˆ’ xiยด
2)
(inner product of vector x and all support points)
E.g.
The Radial basis function kernel
Support vector machines
โ‘ Support Vector machines
โ–ช Linear kernel
โ–ช Polynomial kernel
19
Support vector machines
โ‘ Support Vector machines
โ–ช Radial basis function kernel (RBF)
โ–ช Gamma parameter:
โ–ช Small gammaโ†’ large similarity radius
โ†’ smooth decision boundary
โ–ช Large gamma โ†’ small similarity radius
โ†’ Complex, tightly constrained decision boundary
20
Gamma(g): Kernel width parameter (positive)
0 0
Agenda of Session 10
โ‘ Maximal margin classifier
โ–ช Definition of hyperplane, classifier margin and support vectors.
โ–ช Basics to the optimization function in linear domain
โ‘ Support vector classifier
โ–ช Basics and definition related to support vector classifier accounting for outliers
โ–ช Python code application
โ‘ Support vector machines
โ–ช Introduction of SVM in non-linear domain
โ–ช The concept of kernels
โ–ช Python code application
โ‘ Multi-class classification
โ–ช Two approaches to apply SVM
โ–ช Python code
โ‘ Support vector regression
โ–ช Introduction to the concept and code application.
21
Support vector machines
โ‘ Multi-class classification
โ–ช One-Versus-One Classification
K classes โ†’ Construct ๐ถ๐พ
2
pairs โ†’ Train ๐ถ๐พ
2
SVMsโ†’ Predict the final
class based on the most frequently assigned class.
โ–ช One-Versus-All Classification
K classes โ†’ Split to K pairs (e.g., kth class and the other)โ†’ Train K
SVMsโ†’ Predict the final result based on the highest amount
22
Support vector machines
โ‘ Fruit types classification (one-versus-all)
23
Target_names_fruits = ['apple', 'mandarin', 'orange', 'lemon']
Support vector machines
โ‘ Support Vector regressions
- An extension of the SVM for regression
- This is an extension of the margin used in support vector classifiers to the
regression setting
24
(Cai et al. 2022)
Loss function:
https://doi.org/10.1007/s11804-022-00263-0
Support vector machines
โ‘ Support Vector machines-kernelized
โ–ช Pros:
โ–ช Can perform well on different types of dataset
โ–ช Versatile: different kernel functions can be specified, or custom kernel
can be defined for specific types of data
โ–ช Works well for both high-and low-dimensional data
โ–ช Cons:
โ–ช Efficiency (running speed and memory usage) decreases as training set
size increases(e.g., over 50000 samples)
โ–ช Need careful normalization of input data and parameter tuning
โ–ช Does not provide directly probability estimation
โ–ช Difficult to interpret why a prediction is made.
25
SVMโ€“ Challenge Tasks
โ‘ Train a model by SVM to predict whether a mushroom is poisonous or not, and
find the gamma (g) values which are underfitting, overfitting and the best fitting,
respectively.
โ–ช mushrooms.csv
In this challenge, you need to answer 3 questions based on what you have learned
today for the SVM method and the previous knowledge as well.
Wrap up of the Day
Tak for denne gang!
2
Questions?

More Related Content

Similar to OM-DS-Fall2022-Session10-Support vector machine.pdf

Linear Discrimination Centering on Support Vector Machines
Linear Discrimination Centering on Support Vector MachinesLinear Discrimination Centering on Support Vector Machines
Linear Discrimination Centering on Support Vector Machines
butest
ย 
Introduction to Machine Learning Elective Course
Introduction to Machine Learning Elective CourseIntroduction to Machine Learning Elective Course
Introduction to Machine Learning Elective Course
MayuraD1
ย 
Svm ms
Svm msSvm ms
Svm ms
student
ย 

Similar to OM-DS-Fall2022-Session10-Support vector machine.pdf (20)

Linear Discrimination Centering on Support Vector Machines
Linear Discrimination Centering on Support Vector MachinesLinear Discrimination Centering on Support Vector Machines
Linear Discrimination Centering on Support Vector Machines
ย 
Lec_XX_Support Vector Machine Algorithm.pptx
Lec_XX_Support Vector Machine Algorithm.pptxLec_XX_Support Vector Machine Algorithm.pptx
Lec_XX_Support Vector Machine Algorithm.pptx
ย 
Support vector machine
Support vector machineSupport vector machine
Support vector machine
ย 
Svm map reduce_slides
Svm map reduce_slidesSvm map reduce_slides
Svm map reduce_slides
ย 
Support Vector Machines- SVM
Support Vector Machines- SVMSupport Vector Machines- SVM
Support Vector Machines- SVM
ย 
Support vector machine-SVM's
Support vector machine-SVM'sSupport vector machine-SVM's
Support vector machine-SVM's
ย 
SVM_notes.pdf
SVM_notes.pdfSVM_notes.pdf
SVM_notes.pdf
ย 
lec10svm.ppt
lec10svm.pptlec10svm.ppt
lec10svm.ppt
ย 
Introduction to Machine Learning Elective Course
Introduction to Machine Learning Elective CourseIntroduction to Machine Learning Elective Course
Introduction to Machine Learning Elective Course
ย 
Classification-Support Vector Machines.pptx
Classification-Support Vector Machines.pptxClassification-Support Vector Machines.pptx
Classification-Support Vector Machines.pptx
ย 
lecture_16.pptx
lecture_16.pptxlecture_16.pptx
lecture_16.pptx
ย 
Data Science - Part IX - Support Vector Machine
Data Science - Part IX -  Support Vector MachineData Science - Part IX -  Support Vector Machine
Data Science - Part IX - Support Vector Machine
ย 
Machine Learning workshop by GDSC Amity University Chhattisgarh
Machine Learning workshop by GDSC Amity University ChhattisgarhMachine Learning workshop by GDSC Amity University Chhattisgarh
Machine Learning workshop by GDSC Amity University Chhattisgarh
ย 
sentiment analysis using support vector machine
sentiment analysis using support vector machinesentiment analysis using support vector machine
sentiment analysis using support vector machine
ย 
lec10svm.ppt
lec10svm.pptlec10svm.ppt
lec10svm.ppt
ย 
lec10svm.ppt
lec10svm.pptlec10svm.ppt
lec10svm.ppt
ย 
Svm ms
Svm msSvm ms
Svm ms
ย 
Text Classification with Lucene/Solr, Apache Hadoop and LibSVM
Text Classification with Lucene/Solr, Apache Hadoop and LibSVMText Classification with Lucene/Solr, Apache Hadoop and LibSVM
Text Classification with Lucene/Solr, Apache Hadoop and LibSVM
ย 
Support vector machines
Support vector machinesSupport vector machines
Support vector machines
ย 
Support Vector machine(SVM) and Random Forest
Support Vector machine(SVM) and Random ForestSupport Vector machine(SVM) and Random Forest
Support Vector machine(SVM) and Random Forest
ย 

Recently uploaded

Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
ย 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
kumargunjan9515
ย 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
kumargunjan9515
ย 
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get CytotecAbortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
ย 
Call Girls in G.T.B. Nagar (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7
Call Girls in G.T.B. Nagar  (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7Call Girls in G.T.B. Nagar  (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7
Call Girls in G.T.B. Nagar (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
ย 
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
HyderabadDolls
ย 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
HyderabadDolls
ย 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
ย 
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
ย 

Recently uploaded (20)

Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
ย 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
ย 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
ย 
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts ServiceCall Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
Call Girls In GOA North Goa +91-8588052666 Direct Cash Escorts Service
ย 
๐Ÿ‘‰ Bhilai Call Girls Service Just Call ๐Ÿ‘๐Ÿ‘„6378878445 ๐Ÿ‘๐Ÿ‘„ Top Class Call Girl Ser...
๐Ÿ‘‰ Bhilai Call Girls Service Just Call ๐Ÿ‘๐Ÿ‘„6378878445 ๐Ÿ‘๐Ÿ‘„ Top Class Call Girl Ser...๐Ÿ‘‰ Bhilai Call Girls Service Just Call ๐Ÿ‘๐Ÿ‘„6378878445 ๐Ÿ‘๐Ÿ‘„ Top Class Call Girl Ser...
๐Ÿ‘‰ Bhilai Call Girls Service Just Call ๐Ÿ‘๐Ÿ‘„6378878445 ๐Ÿ‘๐Ÿ‘„ Top Class Call Girl Ser...
ย 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
ย 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
ย 
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get CytotecAbortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
Abortion pills in Doha {{ QATAR }} +966572737505) Get Cytotec
ย 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
ย 
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
ย 
Call Girls in G.T.B. Nagar (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7
Call Girls in G.T.B. Nagar  (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7Call Girls in G.T.B. Nagar  (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7
Call Girls in G.T.B. Nagar (delhi) call me [๐Ÿ”9953056974๐Ÿ”] escort service 24X7
ย 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
ย 
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service AvailableVastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
ย 
Predictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting TechniquesPredictive Precipitation: Advanced Rain Forecasting Techniques
Predictive Precipitation: Advanced Rain Forecasting Techniques
ย 
Charbagh + Female Escorts Service in Lucknow | Starting โ‚น,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting โ‚น,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting โ‚น,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting โ‚น,5K To @25k with A/C...
ย 
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
Belur $ Female Escorts Service in Kolkata (Adult Only) 8005736733 Escort Serv...
ย 
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
Sealdah % High Class Call Girls Kolkata - 450+ Call Girl Cash Payment 8005736...
ย 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
ย 
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Nandurbar [ 7014168258 ] Call Me For Genuine Models...
ย 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
ย 

OM-DS-Fall2022-Session10-Support vector machine.pdf

  • 1. Lecturer: Jie Cai, jiec@iti.sdu.dk OM-DSML Session 10: Support Vector Machines
  • 2. 2 To understand & learn the basic concepts of maximal margin classifier, support vector classifier, support vector machines and their application in sciki-learn by examples. Course Objective James et al, Chapter 9: Support vector machines, P 367-386
  • 3. Agenda of Session 10 โ‘ Maximal margin classifier โ–ช Definition of hyperplane, classifier margin and support vectors. โ–ช Basics of the optimization function in linear domain โ‘ Support vector classifier โ–ช Basics and definition related to support vector classifier accounting for outliers โ–ช Python code โ‘ Support vector machines โ–ช Introduction of SVM in non-linear domain โ–ช The concept of kernels โ–ช Python code โ‘ Multi-class classification โ–ช Two approaches to apply SVM โ–ช Python code โ‘ Support vector regression โ–ช Introduction to the concept and code application. 3
  • 4. Support vector machines โ‘ What is support vector machines (SVM) โ–ช One of the most powerful โ€œblack boxโ€ learning algorithms in ML field โ–ช One of the most widely used ML methods nowadays โ–ช It loosely refers to the maximal margin classifier, the support vector classifier, and the support vector machine โ–ช Maximal margin classifier -Use a hyperplane with a maximal margin to sperate a binary classification problem. โ–ช Support vector classifier (soft margin classifier) -An extension of the maximal margin classifier that can be applied in a broader range of cases, where misclassified samples are allowed. โ–ช Support vector machine -A further extension of the support vector classifier in order to accommodate non- linear class boundaries. 4
  • 5. Support vector machines โ‘ Maximal margin classifier โ–ช What is the hyperplane ? -In a p-dimensional space, a hyperplane is a flat affine subspace of dimension p โˆ’ 1. -E.g., in a 2D space, a hyperplane is defined by the mathematical equation: 5 Figure 9.1. The hyperplane 1+2X1 + 3X2 = 0 is shown.
  • 6. Support vector machines โ‘ Maximal margin classifier - How would you separate these two groups of training examples with a straight line ? Suppose: Training data: X โˆˆ (n,2), เทก ๐’€ โˆˆ(n,1) 6 A sample binary classification problem with two features ๐œท๐ŸŽ + ๐œท๐Ÿ ๐’™๐Ÿ + ๐œท๐Ÿ ๐’™๐Ÿ =0
  • 7. Support vector machines โ‘ Maximal margin classifier - How would you separate these two groups of training examples with a straight line ? We need to train a model: Find a hyperplane, all samples should be satisfied : if defined class value as โ†’ y (๐œท๐ŸŽ + ๐œท๐Ÿ ๐’™๐Ÿ + ๐œท๐Ÿ ๐’™๐Ÿ) >0 แ‰ˆ ๐Ÿ โˆ’๐Ÿ
  • 8. Support vector machines โ‘ Maximal margin classifier โ–ช Margin - Means the plane we found should be the farthest to the nearest samples; - Defined as the width the decision boundary area can be increased before hitting a sample data point. 8 A sample binary classification problem with two features Margin ๐’…๐’Š๐’”๐’• = ๐œท๐ŸŽ + ๐œท๐Ÿ ๐’™๐’Š๐Ÿ + โ‹ฏ + ๐œท๐’‘ ๐’™๐’Š๐’‘ ๐œท๐’‹ ๐Ÿ
  • 9. Support vector machines โ‘ Maximal margin classifier โ–ช Support vectors - Defined as the samples determining such a hyperplane; - The maximal margin hyperplane depends directly on only a small subset of the observations Therefore, the linear classifier with the maximum margin is also called a linear support vector machine (LSVM) 9 A sample binary classification problem with two features Margin
  • 10. Support vector machines โ‘ Construction of the Maximal Margin Classifier The optimization problem: The problem: โ–ช No such linear hyperplanes exit for many cases. โ–ช A soft-margin is needed, allowing outliers. 10
  • 11. Support vector machines โ‘ Maximal margin Classifiers โ–ช Maximal margin classifier is sensitive to individual samples โ–ช Not robust โ–ช Overfitting Therefore, rather than seeking the largest possible margin so that every observation is not only on the correct side of the hyperplane but also on the correct side of the margin, we instead allow some observations to be on the incorrect side of the margin, or even the incorrect side of the hyperplane. 11
  • 12. Support vector machines โ‘ Support Vector Classifiers โ–ช Soft margin classifier - The margin is soft because it can be violated by some of the training observations. 12 ๐๐’Š = แ‰ ๐ŸŽ: ๐‘ด๐‘ด๐‘ช > ๐ŸŽ โˆถ ๐’—๐’Š๐’๐’๐’…๐’‚๐’•๐’†๐’… ๐’Ž๐’‚๐’“๐’ˆ๐’Š๐’ > ๐Ÿ โˆถ ๐’˜๐’“๐’๐’๐’ˆ ๐’”๐’Š๐’…๐’† ๐’๐’‡ ๐’‰๐’š๐’‘๐’†๐’“๐’‘๐’๐’‚๐’ Slack variable Tuning parameter Small C: small margin, less tolerance, low bias but high variance Large C: large margin, large tolerance, high bias but low variance
  • 13. Support vector machines โ‘ Support Vector classifier-linear โ–ช Pros: โ–ช Simple and easy to train โ–ช Fast prediction โ–ช Reasons for prediction are relatively easy to interpret โ–ช Cons: โ–ช For lower-dimensional data, other models may have superior generalization performance โ–ช For classification, data may not be linearly separable (we will talk about more in the next part for non-linear kernels). 13
  • 14. Agenda of Session 10 โ‘ Maximal margin classifier โ–ช Definition of hyperplane, classifier margin and support vectors. โ–ช Basics to the optimization function in linear domain โ‘ Support vector classifier โ–ช Basics and definition related to support vector classifier accounting for outliers โ–ช Python code application โ‘ Support vector machines โ–ช Introduction of SVM in non-linear domain โ–ช The concept of kernels โ–ช Python code โ‘ Multi-class classification โ–ช Two approaches to apply SVM โ–ช Python code application โ‘ Support vector regression โ–ช Introduction to the concept and code application. 14
  • 15. Support vector machines โ‘ Support Vector machines There is still one problem we can not figure out , binary classification with a non- linear boundary. 15 Linear boundary Non-linear boundary Therefore, enlarge the feature space E.g., 2Dโ†’ 3D problem. Or using quadratic, cubic, and even higher-order polynomial functions of the predictors
  • 16. Support vector machines โ‘ Support Vector machines 16 An example of mapping a 2D classification problem to a 3D feature space to make it linear separable
  • 17. Support vector machines โ‘ Support Vector machines 17 An example of mapping a 2D classification problem to a 3D feature space to make it linear separable
  • 18. Support vector machines โ‘ Support Vector Machines - The SVM is an extension of the support vector classifier that results from enlarging the feature space in a specific way, using kernels. โ–ช Kernels - The function that quantifies the similarity of two observations. E.g., for the linear support classifier, 18 similarity (xi, xiยด)=exp(-g xi โˆ’ xiยด 2) (inner product of vector x and all support points) E.g. The Radial basis function kernel
  • 19. Support vector machines โ‘ Support Vector machines โ–ช Linear kernel โ–ช Polynomial kernel 19
  • 20. Support vector machines โ‘ Support Vector machines โ–ช Radial basis function kernel (RBF) โ–ช Gamma parameter: โ–ช Small gammaโ†’ large similarity radius โ†’ smooth decision boundary โ–ช Large gamma โ†’ small similarity radius โ†’ Complex, tightly constrained decision boundary 20 Gamma(g): Kernel width parameter (positive) 0 0
  • 21. Agenda of Session 10 โ‘ Maximal margin classifier โ–ช Definition of hyperplane, classifier margin and support vectors. โ–ช Basics to the optimization function in linear domain โ‘ Support vector classifier โ–ช Basics and definition related to support vector classifier accounting for outliers โ–ช Python code application โ‘ Support vector machines โ–ช Introduction of SVM in non-linear domain โ–ช The concept of kernels โ–ช Python code application โ‘ Multi-class classification โ–ช Two approaches to apply SVM โ–ช Python code โ‘ Support vector regression โ–ช Introduction to the concept and code application. 21
  • 22. Support vector machines โ‘ Multi-class classification โ–ช One-Versus-One Classification K classes โ†’ Construct ๐ถ๐พ 2 pairs โ†’ Train ๐ถ๐พ 2 SVMsโ†’ Predict the final class based on the most frequently assigned class. โ–ช One-Versus-All Classification K classes โ†’ Split to K pairs (e.g., kth class and the other)โ†’ Train K SVMsโ†’ Predict the final result based on the highest amount 22
  • 23. Support vector machines โ‘ Fruit types classification (one-versus-all) 23 Target_names_fruits = ['apple', 'mandarin', 'orange', 'lemon']
  • 24. Support vector machines โ‘ Support Vector regressions - An extension of the SVM for regression - This is an extension of the margin used in support vector classifiers to the regression setting 24 (Cai et al. 2022) Loss function: https://doi.org/10.1007/s11804-022-00263-0
  • 25. Support vector machines โ‘ Support Vector machines-kernelized โ–ช Pros: โ–ช Can perform well on different types of dataset โ–ช Versatile: different kernel functions can be specified, or custom kernel can be defined for specific types of data โ–ช Works well for both high-and low-dimensional data โ–ช Cons: โ–ช Efficiency (running speed and memory usage) decreases as training set size increases(e.g., over 50000 samples) โ–ช Need careful normalization of input data and parameter tuning โ–ช Does not provide directly probability estimation โ–ช Difficult to interpret why a prediction is made. 25
  • 26. SVMโ€“ Challenge Tasks โ‘ Train a model by SVM to predict whether a mushroom is poisonous or not, and find the gamma (g) values which are underfitting, overfitting and the best fitting, respectively. โ–ช mushrooms.csv In this challenge, you need to answer 3 questions based on what you have learned today for the SVM method and the previous knowledge as well.
  • 27. Wrap up of the Day
  • 28. Tak for denne gang! 2 Questions?