Support Vector Machines
History Of SVM
- SVM is related to statistical learning theory
- First introduced in 1992
- Became popular because of its success in handwritten digit recognition
- 1.1% test error rate for SVM. Same error as a perceptron model.
- Also used in very first self-driving cars
- Later bested by deep learning methods
- Note: the meaning of “kernel” is different from other methods
What Is A Good Decision Boundary?
Consider a two-class, linearly separable classification problem
- Many decision boundaries!
- Are all decision boundaries equally good?
Let’s say we have this data. How do we draw the decision boundaries?
Examples Of Bad Decision Boundaries
Which points most define where we should draw a boundary?
Large-Margin Decision Boundary
- The decision boundary should be as far away from the data of both classes as possible
- We should maximize the margin,
- Distance between the origin and the line
is
Finding The Decision Boundary
- Let
be our data set and let be the class label of - The decision boundary should classify all points correctly
- The decision boundary can be found by solving the following constrained optimization problem:
- Minimize
- subject to
- Minimize
- This is a constrained optimization problem
- Quick methods to find the global optimum by quadratic programming
The Quadratic Programming Problem
Many approaches have been proposed
- Most are “interior-point” methods
- Start with an initial solution that can violate the constraints
- Improve this solution by optimizing the objective function and/or reducing the amount of constraint violation
- For SVM, sequential minimal optimization (SMO) seems to be the most popular
- A QP with two variables is trivial to solve
- Each iteration of SMO picks a pair of (
) and solve the QP with these two variables; repeat until convergence
- In practice, we can just regard the QP solver as a “black-box” without bothering how it works
Characteristics Of The Solution
- Many of the
are zero- w is a linear combination of a small number of data points
- This “sparse” representation can be viewed as data compression as in the construction of knn classifier
with non-zero are called support vectors (SV)- The decision boundary is determined only by the SV
- Let
be the indices of the s support vectors - We can write
- For testing with a new data z
- Compute
- Classify z as class 1 if the sum is positive, and class 2 otherwise
- Note: w need not be formed explicitly
- Compute
A Geometrical Interpretation
Non-Linearly Separable Problems
- We allow “error”
in classification; it is based on the output of the discriminant function - ξi approximates the number of misclassified samples
Soft Margin Hyperplane
- If we minimize
, can be computed by are “slack variables” in optimization- Note that
if there is no error for is an upper bound of the number of errors
- We want to minimize:
: tradeoff parameter between error and margin
- The optimization problem becomes:
- Minimize
- subject to
- Minimize
The Optimization Problem
- The dual of this new constrained optimization problem is:
- max.
- subject to
- max.
- w is recovered as
- This is very similar to the optimization problem in the linear separable case, except that there is an upper bound
on now - Once again, a QP solver can be used to find
Extension To Non-linear Decision Boundary
- So far, we have only considered large-margin classifier with a linear decision boundary
- How to generalize it to become nonlinear?
- Key idea: transform
to a higher dimensional space to “make life easier”- Input space: the space the point
are located - Feature space: the space of φ(
) after transformation
- Input space: the space the point
- Why transform?
- Linear operation in the feature space is equivalent to non-linear operation in input space
- Classification can become easier with a proper transformation.
Go over circle inside circle with transformation to polar coordinates.
Transforming The Data
- Note that feature space is usually of higher dimensions in practice
- Computation in the feature space can be costly because it is high dimensional
- The feature space is typically infinite-dimensional!
- The kernel trick comes to rescue
The Kernel Trick
Recall the SVM optimization problem
The data points only appear as the inner product
- max.
- subject to
- max.
As long as we can calculate the inner product in the feature space, we do not need the mapping explicitly
Many common geometric operations (angles, distances) can be expressed by inner products
Define the kernel function
by:
Kernel Functions
- In practical use of SVM, the user specifies the kernel function; the transformation φ(.) is not explicitly stated
- Given a kernel function
, the transformation φ(.) is given by its eigenfunctions (a concept in functional analysis)- Eigenfunctions can be difficult to construct explicitly
- This is why people only specify the kernel function without worrying about the exact transformation
- Another view: kernel function, being an inner product, is really a similarity measure between the objects
Examples of Kernel Functions
- Polynomial kernel with degree
- Radial basis function kernel with width
- Closely related to radial basis function neural networks
- The feature space is infinite-dimensional
- Sigmoid with parameter
and
Modification Due to Kernel Function
- Change all inner products to kernel functions
- For training:
- Original: max.
- With kernel function: max.
- Both: subject to
- Original: max.
Modification Due to Kernel Function
- For testing, the new data z is classified as class 1 if
, and class 2 if - Original:
- With kernel function:
More on Kernel Functions
- Since the training of SVM only requires the value of
, there is no restriction of the form of and can be a sequence or a tree, instead of a feature vector
is just a similarity measure comparing and- For a test object z, the discrimination function essentially is a weighted sum of the similarity between z and a pre-selected set of objects (the support vectors):
- S: the set of support vectors
Example of Non-Linear Transformation
Justification of SVM
- Large margin classifier
- Ridge regression: the term
“shrinks” the parameters towards zero to avoid overfitting - The term the term
can also be viewed as imposing a weight-decay prior on the weight vector
Choosing the Kernel Function
- Probably the most tricky part of using SVM
- The kernel function is important because it creates the kernel matrix, which summarizes all the data
- In practice, a low degree polynomial kernel or RBF kernel with a reasonable width is a good initial try
Go over how to pick an appropriate kernel, and floppiness.
Other Aspects of SVM
- How to use SVM for multi-class classification?
- One can change the QP formulation to become multi-class
- More often, multiple binary classifiers are combined
- One can train multiple one-versus-all classifiers, or combine multiple pairwise classifiers “intelligently”
- How to interpret the SVM discriminant function value as probability?
- By performing logistic regression on the SVM output of a set of data (validation set) that is not used for training
Summary: Steps For Classification
- Prepare the pattern matrix
- Select the kernel function to use
- Select the parameter of the kernel function and the value of C
- You can use the values suggested by the SVM software, or you can set apart a validation set to determine the values of the parameter
- Execute the training algorithm and obtain the
- Unseen data can be classified using the
and the support vectors
Strengths And Weaknesses Of SVM
- Strengths
- Training is relatively easy
- No local optimal, unlike in neural networks
- It scales relatively well to high dimensional data
- Tradeoff between classifier complexity and error can be controlled explicitly
- Non-traditional data like strings and trees can be used as input to SVM, instead of feature vectors
- Training is relatively easy
- Weaknesses
- Need to choose a “good” kernel function.
- Not generative
- Difficult to interpret
- Need fully labelled data
Other Types Of Kernel Methods
- A lesson learnt in SVM: a linear algorithm in the feature space is equivalent to a non-linear algorithm in the input space
- Standard linear algorithms can be generalized to its non-linear version by going to the feature space
- Kernel principal component analysis, kernel independent component analysis, kernel canonical correlation analysis, kernel k-means, 1-class SVM are some examples
Multi-Class Classification
- SVM is basically a two-class classifier
- One can change the QP formulation to allow multi-class classification
- More commonly, the data set is divided into two parts “intelligently” in different ways and a separate SVM is trained for each way of division
- Multi-class classification is done by combining the output of all the SVM classifiers
- Majority rule
- Error correcting code
- Directed acyclic graph
Application - Circulating Tumor Cells
Capture of circulating tumor cells enables assessment of patient metastatic state and chemotherapeutic response
- Found in the blood of metastatic cancer patients
- Approximately 1 CTC per billion blood cells
- CTs have great clinical value
- Liquid biopsy
- Genetic information
- Prognostic
Application - Separating CTCs From Other Blood Cells
Application - Separating CTCs From Other Blood Cells
Implementation
sklearn has implementations for a variety of SVM methods:
sklearn.svm.SVC
- Performs single or multi-class classification
- Multi-class is through one-vs-one scheme
- Multiple kernels available
linear
:polynomial
:rbf
:sigmoid
:
- Performs single or multi-class classification
- Alternative implementations
sklearn.svm.NuSVC
- Additionally provides parameter to control number of support parameters
sklearn.svm.LinearSVC
- Only support for linear kernel, with better scaling/options
- For example can provide l1 or l2 regularization
- Scales better for many samples
Reading & Resources
- 📖: MIT 6.034: Support Vector Machines
- 📖: Computer Age Statistical Inference: Chapter 19
- 💾: sklearn: Support Vector Machines
- 👂: Linear Digressions: Maximal Margin Classifiers
- 👂: Linear Digressions: The Kernel Trick and Support Vector Machines
Review Questions
- What is the core observation underlying SVMs?
- Does the answer for an SVM rely on the exact position of all points? If not, which points most influence the model?
- Where can you find the support vectors in a dataset?
- What is a kernel? What are three common kinds?
- Can you use SVMs for data that can’t be perfectly separated? What do you do if so? What additional tradeoff does this create?
- What is a hyperparameter? How do you find the value of these?
- How is Y represented within an SVM model?
- You use an SVM model with an RBF kernel and a high value for gamma. What does the value of gamma indicate?
- When the C parameter is set to be infinite, which of the following is true?
- Your colleague is using an SVM with poly kernel and notices that the fitting error improves with ever higher degree polynomials. What is happening here? What would you suggest they do?
- Can an SVM model be used with more than two classes? If so, how?