1 / 53

Support Vector Machines

Support Vector Machines. Reading: Ben- Hur and Weston, “A User’s Guide to Support Vector Machines” (linked from class web page). Notation. Assume a binary classification problem: h ( x )  {−1, 1} Instances are represented by vector x   n .

faith
Download Presentation

Support Vector Machines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Support Vector Machines Reading: Ben-Hur and Weston, “A User’s Guide to Support Vector Machines” (linked from class web page)

  2. Notation • Assume a binary classification problem: h (x)  {−1, 1} • Instances are represented by vector x  n. • Training examples: xk= (x1,x2, …,xn) • Training set: S= {(x1, y1), (x2, y2), ..., (xm, ym) | (xk, yk)  n{+1, -1}} Questions on notation...

  3. Here, assume positive and negative instances are to be separated by the hyperplane , where b is the bias. Equation of line: x2 x1

  4. Intuition: The best hyperplanefor future generalization will “maximally” separate the examples (assuming new examples will come from the same distribution)

  5. Definition of Margin Margin is defined as distance from separating hypeplane to nearest training example. Note: Sometimes margin is defined as twice the distance.

  6. Definition of Margin Vapnik (1979) showed that the hyperplane maximizing the margin of S will have minimal VC dimension in the set of all consistent hyperplanes, and will thus be optimal.

  7. Definition of Margin This is an optimization problem! Vapnik (1979) showed that the hyperplane maximizing the margin of S will have minimal VC dimension in the set of all consistent hyperplanes, and will thus be optimal.

  8. Support vectors: Training examples that lie on the margin. http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png

  9. Support vectors: Training examples that lie on the margin. http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png

  10. Support vectors: Training examples that lie on the margin. http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png

  11. Support vectors: Training examples that lie on the margin. http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png

  12. Support vectors: Training examples that lie on the margin. http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png Without changing the problem, we can rescale our data to set a = 1

  13. Support vectors: Training examples that lie on the margin. http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png Without changing the problem, we can rescale our data to set a = 1

  14. Length of the margin margin http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png Without changing the problem, we can rescale our data to set a = 1

  15. Length of the margin margin http://nlp.stanford.edu/IR-book/html/htmledition/img1260.png Without changing the problem, we can rescale our data to set a = 1

  16. w is perpendicular to decision boundary

  17. The length of the margin is • So to maximize the margin, we need to minimize .

  18. Minimizing ||w|| Find w and b by doing the following minimization: This is a quadratic optimization problem.

  19. Minimizing ||w|| Find w and b by doing the following minimization: This is a quadratic optimization problem. Shorthand:

  20. Dual Representation • It turns out that w can be expressed as a linear combination of the training examples: • The results of the SVM training algorithm (involving solving a quadratic programming problem) are the i and the bias b.

  21. SVM Classification • Classify new example x as follows: where | S | = m. (S is the training set)

  22. SVM Classification • Classify new example x as follows: where | S | = m. (S is the training set) • Note that dot product is a kind of “similarity measure”

  23. Example 2 1 1 2 -2 -1 -1 -2

  24. Example Input to SVM optimizer: x1 x2 class 1 1 1 1 2 1 2 1 1 -1 0 -1 0 -1 -1 -1 -1 -1 2 1 1 2 -2 -1 -1 -2

  25. Example Input to SVM optimizer: x1 x2 class 1 1 1 1 2 1 2 1 1 -1 0 -1 0 -1 -1 -1 -1 -1 Output from SVM optimizer: Support vectorα (-1, 0) -.208 (1, 1) .416 (0, -1) -.208 b = -.376 2 1 1 2 -2 -1 -1 -2

  26. Example Input to SVM optimizer: x1 x2 class 1 1 1 1 2 1 2 1 1 -1 0 -1 0 -1 -1 -1 -1 -1 Output from SVM optimizer: Support vectorα (-1, 0) -.208 (1, 1) .416 (0, -1) -.208 b = -.376 2 1 1 2 -2 -1 Weight vector: -1 -2 Compute this Separation line: Sketch this

  27. Example Input to SVM optimizer: x1 x2 class 1 1 1 1 2 1 2 1 1 -1 0 -1 0 -1 -1 -1 -1 -1 Output from SVM optimizer: Support vectorα (-1, 0) -.208 (1, 1) .416 (0, -1) -.208 b = -.376 2 1 1 2 -2 -1 Weight vector: -1 -2 Separation line:

  28. Example 2 1 1 2 -2 -1 -1 Classifying a new point: -2 Compute this

  29. Example 2 1 1 2 -2 -1 -1 Classifying a new point: -2

  30. svm_light Demo

  31. In-Class Exercises

  32. Non-linearly separable training examples • What if the training examples are not linearly separable?

  33. Non-linearly separable training examples • What if the training examples are not linearly separable? • Use old trick: Find a function that maps points to a higher dimensional space (“feature space”) in which they are linearly separable, and do the classification in that higher-dimensional space.

  34. x2 Need to find a function  that will perform such a mapping: : n F Then can find hyperplane in higher dimensional feature space F, and do classification using that hyperplane in higher dimensional space. x1

  35. x2 Need to find a function  that will perform such a mapping: : n F Then can find hyperplane in higher dimensional feature space F, and do classification using that hyperplane in higher dimensional space. x2 x1 x1 x3

  36. Exercise Find : 2  F to create a 3-dimensional feature space in which XOR is linearly separable. I.e., find  (x1, x2) = (x1, x2, x3) so that these points become separable x2 x2 (0, 1) (1, 1) (1, 0) x1 x3 (0, 0) x1

  37. Problem: • Recall that classification of instance x is expressed in terms of dot products of x and support vectors. • The quadratic programming problem of finding the support vectors and coefficients also depends only on dot products between training examples.

  38. So if each xi is replaced by (xi) in these procedures, we will have to calculate (xi) for each i as well as calculate a lot of dot products, (xi) (xj) • In general, if the feature space F is high dimensional, (xi)  (xj) will be expensive to compute.

  39. Second trick: • Suppose that there were some magic function, k(xi, xj) = (xi) (xj) such that k is cheap to compute even though (xi) (xj) is expensive to compute. • Then we wouldn’t need to compute the dot product directly; we’d just need to compute k during both the training and testing phases. • The good news is: such k functions exist! They are called kernel functions, and come from the theory of integral operators.

  40. Example: Polynomial kernel: Suppose x = (x1, x2) andz= (z1,z2).

  41. Example Does the degree-2 polynomial kernel make XOR linearly separable? (0, 1) (1, 1) x2 (1, 0) (0, 0) x1

  42. Recap of SVM algorithm Given training set S = {(x1, y1), (x2, y2), ..., (xm, ym) | (xi, yi)n{+1, -1} • Choose a map : nF, which maps xi to a higher dimensional feature space. (Solves problem that X might not be linearly separable in original space.) • Choose a cheap-to-compute kernel function k(x,z)=(x) (z) (Solves problem that in high dimensional spaces, dot products are very expensive to compute.)

  43. Apply quadratic programming procedure (using the kernel function k) to find a hyperplane (w,b), such that where the (xi)’s are support vectors, the i’s are coefficients, andbis a bias, such that (w, b) is the hyperplane maximizing the margin of the training set in feature space F.

  44. 5. Now, given a new instance, x, find the classification of x by computing

  45. More on Kernels • So far we’ve seen kernels that map instances in nto instances in z where z > n. • One way to create a kernel: Figure out appropriate feature space Φ(x), and find kernel function k which defines inner product on that space. • More practically, we usually don’t know appropriate feature space Φ(x). • What people do in practice is either: • Use one of the “classic” kernels (e.g., polynomial), or • Define their own function that is appropriate for their task, and show that it qualifies as a kernel.

  46. How to define your own kernel • Given training data (x1, x2, ..., xn) • Algorithm for SVM learning uses kernel matrix (also called Gram matrix): • We can choose some function k, and compute the kernel matrix K using the training data. • We just have to guarantee that our kernel defines an inner product on some feature space. • Not as hard as it sounds.

  47. What counts as a kernel? • Mercer’s Theorem: If the kernel matrix K is “symmetric positive definite”, it defines a kernel, that is, it defines an inner product in some feature space. • We don’t even have to know what that feature space is! It can have a huge number of dimensions.

More Related