947 lines
29 KiB
HTML
947 lines
29 KiB
HTML
\
|
|
<!DOCTYPE html>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
|
|
<meta name="description" content="Data Analysis and Machine Learning: Support Vector Machines">
|
|
|
|
<title>Data Analysis and Machine Learning: Support Vector Machines</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- reveal.js: http://lab.hakim.se/reveal-js/ -->
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
|
|
|
|
<link rel="stylesheet" href="reveal.js/css/reveal.css">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/beige.css" id="theme">
|
|
<!--
|
|
<link rel="stylesheet" href="reveal.js/css/reveal.css">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/beige.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/beigesmall.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/serif.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/night.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/moon.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/simple.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/sky.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/darkgray.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/default.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/cbc.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/simula.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/black.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/white.css" id="theme">
|
|
<link rel="stylesheet" href="reveal.js/css/theme/league.css" id="theme">
|
|
-->
|
|
|
|
<!-- For syntax highlighting -->
|
|
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
|
|
|
|
<!-- Printing and PDF exports -->
|
|
<script>
|
|
var link = document.createElement( 'link' );
|
|
link.rel = 'stylesheet';
|
|
link.type = 'text/css';
|
|
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
|
|
document.getElementsByTagName( 'head' )[0].appendChild( link );
|
|
</script>
|
|
|
|
<style type="text/css">
|
|
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
|
|
p.caption { width: 80%; font-size: 60%; font-style: italic; text-align: left; }
|
|
hr.figure { border: 0; width: 80%; border-bottom: 1px solid #aaa}
|
|
.reveal .alert-text-small { font-size: 80%; }
|
|
.reveal .alert-text-large { font-size: 130%; }
|
|
.reveal .alert-text-normal { font-size: 90%; }
|
|
.reveal .alert {
|
|
padding:8px 35px 8px 14px; margin-bottom:18px;
|
|
text-shadow:0 1px 0 rgba(255,255,255,0.5);
|
|
border:5px solid #bababa;
|
|
-webkit-border-radius: 14px; -moz-border-radius: 14px;
|
|
border-radius:14px;
|
|
background-position: 10px 10px;
|
|
background-repeat: no-repeat;
|
|
background-size: 38px;
|
|
padding-left: 30px; /* 55px; if icon */
|
|
}
|
|
.reveal .alert-block {padding-top:14px; padding-bottom:14px}
|
|
.reveal .alert-block > p, .alert-block > ul {margin-bottom:1em}
|
|
/*.reveal .alert li {margin-top: 1em}*/
|
|
.reveal .alert-block p+p {margin-top:5px}
|
|
/*.reveal .alert-notice { background-image: url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_notice.png); }
|
|
.reveal .alert-summary { background-image:url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_summary.png); }
|
|
.reveal .alert-warning { background-image: url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_warning.png); }
|
|
.reveal .alert-question {background-image:url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_question.png); } */
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<!-- Styles for table layout of slides -->
|
|
<style type="text/css">
|
|
td.padding {
|
|
padding-top:20px;
|
|
padding-bottom:20px;
|
|
padding-right:50px;
|
|
padding-left:50px;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
<div class="reveal">
|
|
|
|
<!-- Any section element inside the <div class="slides"> container
|
|
is displayed as a slide -->
|
|
|
|
<div class="slides">
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
TeX: {
|
|
equationNumbers: { autoNumber: "none" },
|
|
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
|
|
}
|
|
});
|
|
</script>
|
|
<script type="text/javascript" async
|
|
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<!-- ------------------- main content ---------------------- -->
|
|
|
|
|
|
|
|
<center><h1 style="text-align: center;">Data Analysis and Machine Learning: Support Vector Machines</h1></center> <!-- document title -->
|
|
|
|
<p>
|
|
<!-- author(s): Morten Hjorth-Jensen -->
|
|
|
|
<center>
|
|
<b>Morten Hjorth-Jensen</b> [1, 2]
|
|
</center>
|
|
|
|
<p> <br>
|
|
<!-- institution(s) -->
|
|
|
|
<center>[1] <b>Department of Physics, University of Oslo</b></center>
|
|
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
|
<br>
|
|
<p> <br>
|
|
<center><h4>Nov 5, 2018</h4></center> <!-- date -->
|
|
<br>
|
|
<p>
|
|
|
|
<center style="font-size:80%">
|
|
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
|
</center>
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec0">Support Vector Machines, overarching aims </h2>
|
|
|
|
<p>
|
|
A Support Vector Machine (SVM) is a very powerful and versatile
|
|
Machine Learning model, capable of performing linear or nonlinear
|
|
classification, regression, and even outlier detection. It is one of
|
|
the most popular models in Machine Learning, and anyone interested in
|
|
Machine Learning should have it in their toolbox. SVMs are
|
|
particularly well suited for classification of complex but small-sized or
|
|
medium-sized datasets.
|
|
|
|
<p>
|
|
The case with two well-separated classes only can be understood in an intuitive way in terms of lines in a two-dimensional space separating the two classes (see figure below).
|
|
|
|
<p>
|
|
The basic mathematics behind the SVM is however less familiar to most of us.
|
|
It relies on the definition of hyperplanes and the
|
|
definition of a <b>margin</b> which separates classes (in case of
|
|
classification problems) of variables. It is also used for regression
|
|
problems.
|
|
|
|
<p>
|
|
With SVMs we distinguish between hard margin and soft margins. The latter introduces a so-called softening parameter to be discussed below.
|
|
We distinguish also between linear and non-linear approaches. The latter are the most frequent ones since it is rather unlikely that we can separate classes easily by say straight lines.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec1">Hyperplanes and all that </h2>
|
|
|
|
<p>
|
|
The theory behind support vector machines (SVM hereafter) is based on
|
|
the mathematical description of so-called hyperplanes. Let us start
|
|
with a two-dimensional case. This will also allow us to introduce our
|
|
first SVM examples. These will be tailored to the case of two specific
|
|
classes, as displayed in the figure here.
|
|
|
|
<p>
|
|
We assume here that our data set can be well separated into two
|
|
domains, where a straight line does the job in the separating the two
|
|
classes. Here the two classes are represented by either crosses or
|
|
circles.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec2">What is a hyperplane? </h2>
|
|
|
|
<p>
|
|
The aim of the SVM algorithm is to find a hyperplane in an \( p \)-dimensional space, where \( p \) is the number of features that distinctly classifies the data points.
|
|
|
|
<p>
|
|
In a \( p \)-dimensional space, a hyperplane is what we call an affine subspace of dimension of \( p-1 \).
|
|
As an example, in two dimension, a hyperplane is simply as straight line while in three dimensions it is
|
|
a two-dimensional subspace, or stated simply, a plane.
|
|
|
|
<p>
|
|
In two dimensions, with the variables \( x_1 \) and \( x_2 \), the hyperplane is defined as
|
|
<p> <br>
|
|
$$
|
|
b+w_1x_1+w_2x_2=0,
|
|
$$
|
|
<p> <br>
|
|
|
|
where \( b \) is the intercept and \( w_1 \) and \( w_2 \) define the elements of a vector orthogonal to the line
|
|
\( b+w_1x_1+w_2x_2=0 \).
|
|
In two dimensions we define the vectors \( \hat{x} =[x1,x2] \) and \( \hat{w}=[w1,w2] \).
|
|
We can then rewrite the above equation as
|
|
<p> <br>
|
|
$$
|
|
\hat{w}^T\hat{x}+b=0.
|
|
$$
|
|
<p> <br>
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec3">A \( p \)-dimensional space of features </h2>
|
|
|
|
<p>
|
|
We limit ourselves to two classes of outputs \( y_i \) and assign these classes the values \( y_i = \pm 1 \).
|
|
In a \( p \)-dimensional space of say \( p \) features we have a hyperplane defines as
|
|
<p> <br>
|
|
$$
|
|
b+wx_1+w_2x_2+\dots +w_px_p=0.
|
|
$$
|
|
<p> <br>
|
|
|
|
If we define a
|
|
matrix \( \hat{X}=\left[\hat{x}_1,\hat{x}_2,\dots, \hat{x}_p\right] \)
|
|
of dimension \( n\times p \), where \( n \) represents the observations for each feature and each vector \( x_i \) is a column vector of the matrix \( \hat{X} \),
|
|
<p> <br>
|
|
$$
|
|
\hat{x}_i = \begin{bmatrix} x_{i1} \\ x_{i2} \\ \dots \\ \dots \\ x_{ip} \end{bmatrix}.
|
|
$$
|
|
<p> <br>
|
|
|
|
If the above condition is not met for a given vector \( \hat{x}_i \) we have
|
|
<p> <br>
|
|
$$
|
|
b+w_1x_{i1}+w_2x_{i}2+\dots +w_px_{ip} >0,
|
|
$$
|
|
<p> <br>
|
|
|
|
if our output \( y_i=1 \).
|
|
In this case we say that \( \hat{x}_i \) lies on one of the sides of the hyperplane and if
|
|
<p> <br>
|
|
$$
|
|
b+w_1x_{i1}+w_2x_{i}2+\dots +w_px_{ip} < 0,
|
|
$$
|
|
<p> <br>
|
|
|
|
for the class of observations \( y_i=-1 \),
|
|
then \( \hat{x}_i \) lies on the other side.
|
|
|
|
<p>
|
|
Equivalently, for the two classes of observations we have
|
|
<p> <br>
|
|
$$
|
|
y_i\left(b+w_1x_{i1}+w_2x_{i}2+\dots +w_px_{ip}\right) > 0.
|
|
$$
|
|
<p> <br>
|
|
|
|
<p>
|
|
When we try to separate hyperplanes, if it exists, we can use it to construct a natural classifier: a test observation is assigned a given class depending on which side of the hyperplane it is located.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec4">The two-dimensional case </h2>
|
|
|
|
<p>
|
|
Let us try to develop our intuition about SVMs by limiting ourselves to a two-dimensional
|
|
plane. To separate the two classes of data points, there are many
|
|
possible lines (hyperplanes if you prefer a more strict naming)
|
|
that could be chosen. Our objective is to find a
|
|
plane that has the maximum margin, i.e the maximum distance between
|
|
data points of both classes. Maximizing the margin distance provides
|
|
some reinforcement so that future data points can be classified with
|
|
more confidence.
|
|
|
|
<p>
|
|
What a linear classifier attempts to accomplish is to split the
|
|
feature space into two half spaces by placing a hyperplane between the
|
|
data points. This hyperplane will be our decision boundary. All
|
|
points on one side of the plane will belong to class one and all points
|
|
on the other side of the plane will belong to the second class two.
|
|
|
|
<p>
|
|
Unfortunately there are many ways in which we can place a hyperplane
|
|
to divide the data. Below is an example of two candidate hyperplanes
|
|
for our data sample.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec5">Getting into the details </h2>
|
|
|
|
<p>
|
|
Let us define the function
|
|
<p> <br>
|
|
$$
|
|
f(x) = \hat{w}^T\hat{x}+b = 0,
|
|
$$
|
|
<p> <br>
|
|
|
|
as the function that determines the line \( L \) that separates two classes (our two features), see the figure here.
|
|
|
|
<p>
|
|
Any point defined by \( \hat{x}_i \) and \( \hat{x}_2 \) on the line \( L \) will satisfy \( \hat{w}^T(\hat{x}_1-\hat{x}_2)=0 \).
|
|
|
|
<p>
|
|
The signed distance \( \delta \) from any point defined by a vector \( \hat{x} \) and a point \( \hat{x}_0 \) on the line \( L \) is then
|
|
<p> <br>
|
|
$$
|
|
\delta = \frac{1}{\vert\vert \hat{w}\vert\vert}(\hat{w}^T\hat{x}+b).
|
|
$$
|
|
<p> <br>
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec6">First attempt at a minimization approach </h2>
|
|
|
|
<p>
|
|
How do we find the parameter \( b \) and the vector \( \hat{w} \)? What we could
|
|
do is to define a cost function which now contains the set of all
|
|
misclassified points \( M \) and attempt to minimize this function
|
|
|
|
<p> <br>
|
|
$$
|
|
C(\hat{w},b) = -\sum_{i\in M} y_i(\hat{w}^T\hat{x}_i+b).
|
|
$$
|
|
<p> <br>
|
|
|
|
<p>
|
|
We could now for example define all values \( y_i =1 \) as misclassified in case we have \( \hat{w}^T\hat{x}_i+b < 0 \) and the opposite if we have \( y_i=-1 \). Taking the derivatives gives us
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial C}{\partial b} = -\sum_{i\in M} y_i,
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial C}{\partial \hat{w}} = -\sum_{i\in M} y_ix_i.
|
|
$$
|
|
<p> <br>
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec7">Solving the equations </h2>
|
|
|
|
<p>
|
|
We can now use the Newton-Raphson method or gradient descent to solve the equations
|
|
<p> <br>
|
|
$$
|
|
b \leftarrow b +\eta \frac{\partial C}{\partial b},
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
\hat{w} \leftarrow \hat{w} +\eta \frac{\partial C}{\partial \hat{w}},
|
|
$$
|
|
<p> <br>
|
|
|
|
where \( \eta \) is our by now well-known learning rate.
|
|
|
|
<p>
|
|
There are however problems with this approach, although it looks
|
|
pretty straightforward to implement. In case we separate our data into
|
|
two distinct classes, we may up with many possible lines, as indicated
|
|
in the figure and shown by running the following program. For small
|
|
gaps between the entries, we may also end up needing many iterations
|
|
before the solutions converge and if the data cannot be separated
|
|
properly into two distinct classes, we may not experience a converge
|
|
at all.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec8">A better approach </h2>
|
|
|
|
<p>
|
|
A better approach is rather to try to define a large margin between
|
|
the two classes (if they are well separated from the beginning).
|
|
|
|
<p>
|
|
Thus, we wish to find a margin \( M \) with \( \hat{w} \) normalized to
|
|
\( \vert\vert \hat{w}\vert\vert =1 \) subject to the condition
|
|
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b) \geq M \hspace{0.1cm}\forall i=1,2,\dots, p.
|
|
$$
|
|
<p> <br>
|
|
|
|
All points are thus at a signed distance from the decision boundary defined by the line \( L \). The parameters \( b \) and \( w_1 \) and \( w_2 \) define this line.
|
|
|
|
<p>
|
|
We seek thus the largest value \( M \) defined by
|
|
<p> <br>
|
|
$$
|
|
\frac{1}{\vert \vert \hat{w}\vert\vert}y_i(\hat{w}^T\hat{x}_i+b) \geq M \hspace{0.1cm}\forall i=1,2,\dots, n,
|
|
$$
|
|
<p> <br>
|
|
|
|
or just
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b) \geq M\vert \vert \hat{w}\vert\vert \hspace{0.1cm}\forall i.
|
|
$$
|
|
<p> <br>
|
|
|
|
If we scale the equation so that \( \vert \vert \hat{w}\vert\vert = 1/M \), we have to find the minimum of
|
|
\( \hat{w}^T\hat{w}=\vert \vert \hat{w}\vert\vert \) (the norm) subject to the condition
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b) \geq 1 \hspace{0.1cm}\forall i.
|
|
$$
|
|
<p> <br>
|
|
|
|
<p>
|
|
We have thus defined our margin as the invers of the norm of \( \hat{w} \). We want to minimize the norm in order to have a as large as possible margin \( M \). Before we proceed, we need to remind ourselves about Lagrangian multipliers.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec9">A quick reminder on Lagrangian multipliers </h2>
|
|
|
|
<p>
|
|
Consider a function of three independent variables \( f(x,y,z) \) . For the function \( f \) to be an
|
|
extreme we have
|
|
<p> <br>
|
|
$$
|
|
df=0.
|
|
$$
|
|
<p> <br>
|
|
|
|
A necessary and sufficient condition is
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial f}{\partial x} =\frac{\partial f}{\partial y}=\frac{\partial f}{\partial z}=0,
|
|
$$
|
|
<p> <br>
|
|
|
|
due to
|
|
<p> <br>
|
|
$$
|
|
df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz.
|
|
$$
|
|
<p> <br>
|
|
|
|
In many problems the variables \( x,y,z \) are often subject to constraints (such as those above for the margin)
|
|
so that they are no longer all independent. It is possible at least in principle to use each
|
|
constraint to eliminate one variable
|
|
and to proceed with a new and smaller set of independent varables.
|
|
|
|
<p>
|
|
The use of so-called Lagrangian multipliers is an alternative technique when the elimination
|
|
of variables is incovenient or undesirable. Assume that we have an equation of constraint on
|
|
the variables \( x,y,z \)
|
|
<p> <br>
|
|
$$
|
|
\phi(x,y,z) = 0,
|
|
$$
|
|
<p> <br>
|
|
|
|
resulting in
|
|
<p> <br>
|
|
$$
|
|
d\phi = \frac{\partial \phi}{\partial x}dx+\frac{\partial \phi}{\partial y}dy+\frac{\partial \phi}{\partial z}dz =0.
|
|
$$
|
|
<p> <br>
|
|
|
|
Now we cannot set anymore
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial f}{\partial x} =\frac{\partial f}{\partial y}=\frac{\partial f}{\partial z}=0,
|
|
$$
|
|
<p> <br>
|
|
|
|
if \( df=0 \) is wanted
|
|
because there are now only two independent variables! Assume \( x \) and \( y \) are the independent
|
|
variables.
|
|
Then \( dz \) is no longer arbitrary.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec10">Adding the muliplier </h2>
|
|
|
|
<p>
|
|
However, we can add to
|
|
<p> <br>
|
|
$$
|
|
df = \frac{\partial f}{\partial x}dx+\frac{\partial f}{\partial y}dy+\frac{\partial f}{\partial z}dz,
|
|
$$
|
|
<p> <br>
|
|
|
|
a multiplum of \( d\phi \), viz. \( \lambda d\phi \), resulting in
|
|
<p> <br>
|
|
$$
|
|
df+\lambda d\phi = (\frac{\partial f}{\partial z}+\lambda
|
|
\frac{\partial \phi}{\partial x})dx+(\frac{\partial f}{\partial y}+\lambda\frac{\partial \phi}{\partial y})dy+
|
|
(\frac{\partial f}{\partial z}+\lambda\frac{\partial \phi}{\partial z})dz =0.
|
|
$$
|
|
<p> <br>
|
|
|
|
Our multiplier is chosen so that
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial f}{\partial z}+\lambda\frac{\partial \phi}{\partial z} =0.
|
|
$$
|
|
<p> <br>
|
|
|
|
<p>
|
|
We need to remember that we took \( dx \) and \( dy \) to be arbitrary and thus we must have
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial f}{\partial x}+\lambda\frac{\partial \phi}{\partial x} =0,
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial f}{\partial y}+\lambda\frac{\partial \phi}{\partial y} =0.
|
|
$$
|
|
<p> <br>
|
|
|
|
When all these equations are satisfied, \( df=0 \). We have four unknowns, \( x,y,z \) and
|
|
\( \lambda \). Actually we want only \( x,y,z \), \( \lambda \) needs not to be determined,
|
|
it is therefore often called
|
|
Lagrange's undetermined multiplier.
|
|
If we have a set of constraints \( \phi_k \) we have the equations
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial f}{\partial x_i}+\sum_k\lambda_k\frac{\partial \phi_k}{\partial x_i} =0.
|
|
$$
|
|
<p> <br>
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec11">Setting up the problem </h2>
|
|
In order to solve the above problem, we define the following Lagrangian function to be minimized
|
|
<p> <br>
|
|
$$
|
|
{\cal L}(\lambda,b,\hat{w})=\frac{1}{2}\hat{w}^T\hat{w}-\sum_{i=1}^n\lambda_i\left[y_i(\hat{w}^T\hat{x}_i+b)-1\right],
|
|
$$
|
|
<p> <br>
|
|
|
|
where \( \lambda_i \) is a so-called Lagrange multiplier subject to the condition \( \lambda_i \geq 0 \).
|
|
|
|
<p>
|
|
Taking the derivatives with respect to \( b \) and \( \hat{w} \) we obtain
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0,
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial {\cal L}}{\partial \hat{w}} = 0 = \hat{w}-\sum_{i} \lambda_iy_i\hat{x}_i.
|
|
$$
|
|
<p> <br>
|
|
|
|
Inserting these constraints into the equation for \( {\cal L} \) we obtain
|
|
<p> <br>
|
|
$$
|
|
{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\hat{x}_i^T\hat{x}_j,
|
|
$$
|
|
<p> <br>
|
|
|
|
subject to the constraints \( \lambda_i\geq 0 \) and \( \sum_i\lambda_iy_i=0 \).
|
|
We must in addition satisfy the <a href="https://en.wikipedia.org/wiki/Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions" target="_blank">Karush-Kuhn-Tucker</a> (KKT) condition
|
|
<p> <br>
|
|
$$
|
|
\lambda_i\left[y_i(\hat{w}^T\hat{x}_i+b) -1\right] \hspace{0.1cm}\forall i.
|
|
$$
|
|
<p> <br>
|
|
|
|
|
|
<ol>
|
|
<p><li> If \( \lambda_i > 0 \), then \( y_i(\hat{w}^T\hat{x}_i+b)=1 \) and we say that \( x_i \) is on the boundary.</li>
|
|
<p><li> If \( y_i(\hat{w}^T\hat{x}_i+b)> 1 \), we say \( x_i \) is not on the boundary and we set \( \lambda_i=0 \).</li>
|
|
</ol>
|
|
<p>
|
|
|
|
When \( \lambda_i > 0 \), the vectors \( \hat{x}_i \) are called support vectors. They are the vectors closest to the line (or hyperplane) and define the margin \( M \).
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec12">The problem to solve </h2>
|
|
|
|
<p>
|
|
We can rewrite
|
|
<p> <br>
|
|
$$
|
|
{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\hat{x}_i^T\hat{x}_j,
|
|
$$
|
|
<p> <br>
|
|
|
|
and its constraints in terms of a matrix-vector problem where we minimize w.r.t. \( \lambda \) the following problem
|
|
<p> <br>
|
|
$$
|
|
\frac{1}{2} \hat{\lambda}^T\begin{bmatrix} y_1y_1\hat{x}_1^T\hat{x}_1 & y_1y_2\hat{x}_1^T\hat{x}_2 & \dots & \dots & y_1y_n\hat{x}_1^T\hat{x}_n \\
|
|
y_2y_1\hat{x}_2^T\hat{x}_1 & y_2y_2\hat{x}_2^T\hat{x}_2 & \dots & \dots & y_1y_n\hat{x}_2^T\hat{x}_n \\
|
|
\dots & \dots & \dots & \dots & \dots \\
|
|
\dots & \dots & \dots & \dots & \dots \\
|
|
y_ny_1\hat{x}_n^T\hat{x}_1 & y_ny_2\hat{x}_n^T\hat{x}_2 & \dots & \dots & y_ny_n\hat{x}_n^T\hat{x}_n \\
|
|
\end{bmatrix}\hat{\lambda}-\mathbb{1}\hat{\lambda},
|
|
$$
|
|
<p> <br>
|
|
|
|
subject to \( \hat{y}^T\hat{\lambda}=0 \). Here we defined the vectors \( \hat{\lambda} =[\lambda_1,\lambda_2,\dots,\lambda_n] \) and
|
|
\( \hat{y}=[y_1,y_2,\dots,y_n] \).
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec13">The last steps </h2>
|
|
|
|
<p>
|
|
Solving the above problem, yields the values of \( \lambda_i \).
|
|
To find the coefficients of your hyperplane we need simply to compute
|
|
<p> <br>
|
|
$$
|
|
\hat{w}=\sum_{i} \lambda_iy_i\hat{x}_i.
|
|
$$
|
|
<p> <br>
|
|
|
|
With our vector \( \hat{w} \) we can in turn find the value of the intercept \( b \) (here in two dimensions) via
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b)=1,
|
|
$$
|
|
<p> <br>
|
|
|
|
resulting in
|
|
<p> <br>
|
|
$$
|
|
b = \frac{1}{y_i}-\hat{w}^T\hat{x}_i.
|
|
$$
|
|
<p> <br>
|
|
|
|
With our hyperplane coefficients we can use our classifier to assign any observation by simply using
|
|
<p> <br>
|
|
$$
|
|
y_i = \mathrm{sign}(\hat{w}^T\hat{x}_i+b).
|
|
$$
|
|
<p> <br>
|
|
|
|
Below we discuss how to find the optimal values of \( \lambda_i \). Before we proceed however, we discuss now the so-called soft classifier.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec14">A soft classifier </h2>
|
|
|
|
<p>
|
|
Till now, the margin is strictly defined by the support vectors. This defines what is called a hard classifier, that is the margins are well defined.
|
|
|
|
<p>
|
|
Suppose now that classes overlap in feature space, as shown in the
|
|
figure here. One way to deal with this problem before we define the
|
|
so-called <b>kernel approach</b>, is to allow a kind of slack in the sense
|
|
that we allow some points to be on the wrong side of the margin.
|
|
|
|
<p>
|
|
We introduce thus the so-called <b>slack</b> variables \( \hat{\xi} =[\xi_1,x_2,\dots,x_n] \) and
|
|
modify our previous equation
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b)=1,
|
|
$$
|
|
<p> <br>
|
|
|
|
to
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b)=1-\xi_i,
|
|
$$
|
|
<p> <br>
|
|
|
|
with the requirement \( \xi_i\geq 0 \). The total violation is now \( \sum_i\xi \).
|
|
The value \( \xi_i \) in the constraint the last constraint corresponds to the amount by which the prediction
|
|
\( y_i(\hat{w}^T\hat{x}_i+b)=1 \) is on the wrong side of its margin. Hence by bounding the sum \( \sum_i \xi_i \),
|
|
we bound the total amount by which predictions fall on the wrong side of their margins.
|
|
|
|
<p>
|
|
Misclassifications occur when \( \xi_i > 1 \). Thus bounding the total sum by some value \( C \) bounds in turn the total number of
|
|
misclassifications.
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec15">Soft optmization problem </h2>
|
|
|
|
<p>
|
|
This has in turn the consequences that we change our optmization problem to finding the minimum of
|
|
<p> <br>
|
|
$$
|
|
{\cal L}=\frac{1}{2}\hat{w}^T\hat{w}-\sum_{i=1}^n\lambda_i\left[y_i(\hat{w}^T\hat{x}_i+b)-(1-\xi_)\right]+C\sum_{i=1}^n\xi_i-\sum_{i=1}^n\gamma_i\xi_i,
|
|
$$
|
|
<p> <br>
|
|
|
|
subject to
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b)=1-\xi_i \hspace{0.1cm}\forall i,
|
|
$$
|
|
<p> <br>
|
|
|
|
with the requirement \( \xi_i\geq 0 \).
|
|
|
|
<p>
|
|
Taking the derivatives with respect to \( b \) and \( \hat{w} \) we obtain
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial {\cal L}}{\partial b} = -\sum_{i} \lambda_iy_i=0,
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
\frac{\partial {\cal L}}{\partial \hat{w}} = 0 = \hat{w}-\sum_{i} \lambda_iy_i\hat{x}_i,
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
\lambda_i = C-\gamma_i \hspace{0.1cm}\forall i.
|
|
$$
|
|
<p> <br>
|
|
|
|
Inserting these constraints into the equation for \( {\cal L} \) we obtain the same equation as before
|
|
<p> <br>
|
|
$$
|
|
{\cal L}=\sum_i\lambda_i-\frac{1}{2}\sum_{ij}^n\lambda_i\lambda_jy_iy_j\hat{x}_i^T\hat{x}_j,
|
|
$$
|
|
<p> <br>
|
|
|
|
but now subject to the constraints \( \lambda_i\geq 0 \), \( \sum_i\lambda_iy_i=0 \) and \( 0\leq\lambda_i \leq C \).
|
|
We must in addition satisfy the Karush-Kuhn-Tucker condition which now reads
|
|
<p> <br>
|
|
$$
|
|
\lambda_i\left[y_i(\hat{w}^T\hat{x}_i+b) -(1-\xi_)\right]=0 \hspace{0.1cm}\forall i,
|
|
$$
|
|
<p> <br>
|
|
|
|
<p> <br>
|
|
$$
|
|
\gamma_i\xi_i = 0,
|
|
$$
|
|
<p> <br>
|
|
|
|
and
|
|
<p> <br>
|
|
$$
|
|
y_i(\hat{w}^T\hat{x}_i+b) -(1-\xi_) \geq 0 \hspace{0.1cm}\forall i.
|
|
$$
|
|
<p> <br>
|
|
</section>
|
|
|
|
|
|
<section>
|
|
<h2 id="___sec16">Kernels and non-linearity </h2>
|
|
</section>
|
|
|
|
|
|
|
|
</div> <!-- class="slides" -->
|
|
</div> <!-- class="reveal" -->
|
|
|
|
<script src="reveal.js/lib/js/head.min.js"></script>
|
|
<script src="reveal.js/js/reveal.js"></script>
|
|
|
|
<script>
|
|
// Full list of configuration options available here:
|
|
// https://github.com/hakimel/reveal.js#configuration
|
|
Reveal.initialize({
|
|
|
|
// Display navigation controls in the bottom right corner
|
|
controls: true,
|
|
|
|
// Display progress bar (below the horiz. slider)
|
|
progress: true,
|
|
|
|
// Display the page number of the current slide
|
|
slideNumber: true,
|
|
|
|
// Push each slide change to the browser history
|
|
history: false,
|
|
|
|
// Enable keyboard shortcuts for navigation
|
|
keyboard: true,
|
|
|
|
// Enable the slide overview mode
|
|
overview: true,
|
|
|
|
// Vertical centering of slides
|
|
//center: true,
|
|
center: false,
|
|
|
|
// Enables touch navigation on devices with touch input
|
|
touch: true,
|
|
|
|
// Loop the presentation
|
|
loop: false,
|
|
|
|
// Change the presentation direction to be RTL
|
|
rtl: false,
|
|
|
|
// Turns fragments on and off globally
|
|
fragments: true,
|
|
|
|
// Flags if the presentation is running in an embedded mode,
|
|
// i.e. contained within a limited portion of the screen
|
|
embedded: false,
|
|
|
|
// Number of milliseconds between automatically proceeding to the
|
|
// next slide, disabled when set to 0, this value can be overwritten
|
|
// by using a data-autoslide attribute on your slides
|
|
autoSlide: 0,
|
|
|
|
// Stop auto-sliding after user input
|
|
autoSlideStoppable: true,
|
|
|
|
// Enable slide navigation via mouse wheel
|
|
mouseWheel: false,
|
|
|
|
// Hides the address bar on mobile devices
|
|
hideAddressBar: true,
|
|
|
|
// Opens links in an iframe preview overlay
|
|
previewLinks: false,
|
|
|
|
// Transition style
|
|
transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
|
|
|
|
// Transition speed
|
|
transitionSpeed: 'default', // default/fast/slow
|
|
|
|
// Transition style for full page slide backgrounds
|
|
backgroundTransition: 'default', // default/none/slide/concave/convex/zoom
|
|
|
|
// Number of slides away from the current that are visible
|
|
viewDistance: 3,
|
|
|
|
// Parallax background image
|
|
//parallaxBackgroundImage: '', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'"
|
|
|
|
// Parallax background size
|
|
//parallaxBackgroundSize: '' // CSS syntax, e.g. "2100px 900px"
|
|
|
|
theme: Reveal.getQueryHash().theme, // available themes are in reveal.js/css/theme
|
|
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
|
|
|
|
});
|
|
|
|
Reveal.initialize({
|
|
dependencies: [
|
|
// Cross-browser shim that fully implements classList - https://github.com/eligrey/classList.js/
|
|
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
|
|
|
|
// Interpret Markdown in <section> elements
|
|
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
|
|
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
|
|
|
|
// Syntax highlight for <code> elements
|
|
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
|
|
|
|
// Zoom in and out with Alt+click
|
|
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
|
|
|
|
// Speaker notes
|
|
{ src: 'reveal.js/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
|
|
|
|
// Remote control your reveal.js presentation using a touch device
|
|
//{ src: 'reveal.js/plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } },
|
|
|
|
// MathJax
|
|
//{ src: 'reveal.js/plugin/math/math.js', async: true }
|
|
]
|
|
});
|
|
|
|
Reveal.initialize({
|
|
|
|
// The "normal" size of the presentation, aspect ratio will be preserved
|
|
// when the presentation is scaled to fit different resolutions. Can be
|
|
// specified using percentage units.
|
|
width: 1170, // original: 960,
|
|
height: 700,
|
|
|
|
// Factor of the display size that should remain empty around the content
|
|
margin: 0.1,
|
|
|
|
// Bounds for smallest/largest possible scale to apply to content
|
|
minScale: 0.2,
|
|
maxScale: 1.0
|
|
|
|
});
|
|
</script>
|
|
|
|
<!-- begin footer logo
|
|
<div style="position: absolute; bottom: 0px; left: 0; margin-left: 0px">
|
|
<img src="somelogo.png">
|
|
</div>
|
|
end footer logo -->
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|