440 likes | 735 Views
Machine Learning. Support Vector Machines. Perceptron Revisited: Linear Separators. Binary classification can be viewed as the task of separating classes in feature space:. w T x + b = 0. w T x + b > 0. w T x + b < 0. g ( x ) = sign( w T x + b ). Linear Discriminant Function.
E N D
Machine Learning Support Vector Machines
Perceptron Revisited: Linear Separators • Binary classification can be viewed as the task of separating classes in feature space: wTx + b = 0 wTx + b > 0 wTx + b < 0 g(x) = sign(wTx + b)
Linear Discriminant Function • g(x) is a linear function: x2 wT x + b > 0 • A hyper-plane in the feature space wT x + b = 0 n • (Unit-length) normal vector of the hyper-plane: x1 wT x + b < 0
denotes +1 denotes -1 Linear Discriminant Function • How would you classify these points using a linear discriminant function in order to minimize the error rate? x2 • Infinite number of answers! x1
denotes +1 denotes -1 Linear Discriminant Function • How would you classify these points using a linear discriminant function in order to minimize the error rate? x2 • Infinite number of answers! x1
denotes +1 denotes -1 Linear Discriminant Function • How would you classify these points using a linear discriminant function in order to minimize the error rate? x2 • Infinite number of answers! x1
denotes +1 denotes -1 Linear Discriminant Function • How would you classify these points using a linear discriminant function in order to minimize the error rate? x2 • Infinite number of answers! • Which one is the best? x1
denotes +1 denotes -1 Large Margin Linear Classifier • The linear discriminant function (classifier) with the maximum margin is the best x2 Margin “safe zone” • Margin is defined as the width that the boundary could be increased by before hitting a data point • Why it is the best? • Robust to outliners and thus strong generalization ability x1
Classification Margin • Distance from example xi to the separator is • Examples closest to the hyperplane are support vectors. • Marginρof the separator is the distance between support vectors. ρ r
Maximum Margin Classification • Maximizing the margin is good according to intuition and PAC theory. • Implies that only support vectors matter; other training examples are ignorable.
denotes +1 denotes -1 x+ x+ x- Support Vectors Large Margin Linear Classifier • We know that x2 Margin wT x + b = 1 wT x + b = 0 wT x + b = -1 • The margin width is: n x1
Linear SVMs Mathematically (cont.) • Then we can formulate the quadratic optimization problem: Which can be reformulated as: Find w and b such that is maximized and for all (xi, yi), i=1..n : yi(wTxi+ b)≥ 1 Find w and b such that Φ(w) = ||w||2=wTw is minimized and for all (xi, yi), i=1..n : yi (wTxi+ b)≥ 1
Solving the Optimization Problem • Need to optimize a quadratic function subject to linear constraints. • Quadratic optimization problems are a well-known class of mathematical programming problems for which several (non-trivial) algorithms exist. • The solution involves constructing a dual problem where a Lagrange multiplierαi is associated with every inequality constraint in the primal (original) problem: Find w and b such that Φ(w) =wTw is minimized and for all (xi, yi),i=1..n: yi (wTxi+ b)≥ 1 Find α1…αnsuch that Q(α) =Σαi- ½ΣΣαiαjyiyjxiTxjis maximized and (1)Σαiyi= 0 (2) αi≥ 0 for all αi
The Optimization Problem Solution • Given a solution α1…αnto the dual problem, solution to the primal is: • Each non-zero αi indicates that corresponding xi is a support vector. • Then the classifying function is (note that we don’t need w explicitly): • Notice that it relies on an inner product between the test point xand the support vectors xi • Also keep in mind that solving the optimization problem involved computing the inner products xiTxjbetween all training points. w =Σαiyixib = yk - ΣαiyixiTxk for any αk > 0 f(x) = ΣαiyixiTx + b
Soft Margin Classification • What if the training set is not linearly separable? • Slack variablesξican be added to allow misclassification of difficult or noisy examples, resulting margin called soft. What should our quadratic optimization criterion be? Minimize ξi ξi
Soft Margin Classification Mathematically • The old formulation: • Modified formulation incorporates slack variables: • Parameter C can be viewed as a way to control overfitting: it “trades off” the relative importance of maximizing the margin and fitting the training data. Find w and b such that Φ(w) =wTw is minimized and for all (xi,yi),i=1..n: yi (wTxi+ b)≥ 1 Find w and b such that Φ(w) =wTw + CΣξi is minimized and for all (xi,yi),i=1..n: yi (wTxi+ b)≥ 1 – ξi, , ξi≥ 0
Non-linear SVMs • Datasets that are linearly separable with some noise work out great: • But what are we going to do if the dataset is just too hard? • How about… mapping data to a higher-dimensional space: x 0 x 0 x2 x 0
Non-linear SVMs: Feature spaces • General idea: the original feature space can always be mapped to some higher-dimensional feature space where the training set is separable: Φ: x→φ(x)
The “Kernel Trick” • The linear classifier relies on inner product between vectors K(xi,xj)=xiTxj • If every datapoint is mapped into high-dimensional space via some transformation Φ: x→φ(x), the inner product becomes: K(xi,xj)= φ(xi)Tφ(xj) • A kernel function is a function that is equivalent to an inner product in some feature space. • Example: 2-dimensional vectors x=[x1 x2]; let K(xi,xj)=(1 + xiTxj)2, Need to show that K(xi,xj)= φ(xi)Tφ(xj): K(xi,xj)=(1 + xiTxj)2,= 1+ xi12xj12 + 2 xi1xj1xi2xj2+ xi22xj22 + 2xi1xj1 + 2xi2xj2= = [1 xi12 √2 xi1xi2 xi22 √2xi1 √2xi2]T [1 xj12 √2 xj1xj2 xj22 √2xj1 √2xj2] = = φ(xi)Tφ(xj), where φ(x) = [1 x12 √2 x1x2 x22 √2x1 √2x2] • Thus, a kernel function implicitly maps data to a high-dimensional space (without the need to compute each φ(x) explicitly).
What Functions are Kernels? • For some functions K(xi,xj) checking that K(xi,xj)= φ(xi)Tφ(xj) can be cumbersome. • Mercer’s theorem: Every semi-positive definite symmetric function is a kernel • Semi-positive definite symmetric functions correspond to a semi-positive definite symmetric Gram matrix: K= For any non-zero vector x, xTKx>0
Examples of Kernel Functions • Linear: K(xi,xj)= xi Txj • Polynomial of power p: K(xi,xj)= (1+xi Txj)p • Gaussian (radial-basis function network): • Sigmoid: K(xi,xj)= tanh(β0xi Txj + β1)
Support Vector Machine: Algorithm • 1. Choose a kernel function • 2. Choose a value for C • 3. Solve the quadratic programming problem (many software packages available) • 4. Construct the discriminant function from the support vectors
Some Issues • Choice of kernel - Gaussian or polynomial kernel are the mostly used non-linear kernels - if ineffective, more elaborate kernels are needed - domain experts can give assistance in formulating appropriate similarity measures • Choice of kernel parameters - e.g. σ in Gaussian kernel - σ is the distance between closest points with different classifications - In the absence of reliable criteria, applications rely on the use of a validation set or cross-validation to set such parameters. • Optimization criterion – Hard margin v.s. Soft margin - a lengthy series of experiments in which various parameters are tested
Why Is SVM Effective on High Dimensional Data? • The complexity of trained classifier is characterized by the # of support vectors rather than the dimensionality of the data • The support vectors are the essential or critical training examples —they lie closest to the decision boundary • If all other training examples are removed and the training is repeated, the same separating hyperplane would be found • The number of support vectors found can be used to compute an (upper) bound on the expected error rate of the SVM classifier, which is independent of the data dimensionality • Thus, an SVM with a small number of support vectors can have good generalization, even when the dimensionality of the data is high October 30, 2014 Data Mining: Concepts and Techniques 24
SVM applications • SVMs were originally proposed by Boser, Guyon and Vapnik in 1992 and gained increasing popularity in late 1990s. • SVMs are currently among the best performers for a number of classification tasks ranging from text to genomic data. • SVMs can be applied to complex data types beyond feature vectors (e.g. graphs, sequences, relational data) by designing kernel functions for such data. • SVM techniques have been extended to a number of tasks such as regression [Vapnik et al. ’97], principal component analysis [Schölkopf et al. ’99], etc. • Most popular optimization algorithms for SVMs use decomposition to hill-climb over a subset of αi’s at a time, e.g. SMO [Platt ’99] and [Joachims ’99] • Tuning SVMs remains a black art: selecting a specific kernel and parameters is usually done in a try-and-see manner.
SVM vs. Neural Network SVM Relatively new concept Deterministic algorithm Nice Generalization properties Hard to learn – learned in batch mode using quadratic programming techniques, but faster with good optimization methods Using kernels can learn very complex functions Neural Network Relatively old Nondeterministic algorithm Generalizes well but doesn’t have strong mathematical foundation Can easily be learned in incremental fashion To learn complex functions—use multilayer perceptron (not that trivial)
Summary: Support Vector Machine • 1. Large Margin Classifier • Better generalization ability & less over-fitting • 2. The Kernel Trick • Map data points to higher dimensional space in order to make them linearly separable. • Since only dot product is used, we do not need to represent the mapping explicitly.
SVM resources • http://www.kernel-machines.org • http://www.csie.ntu.edu.tw/~cjlin/libsvm/
Model Evaluation • Metrics for Performance Evaluation • How to evaluate the performance of a model? • Methods for Performance Evaluation • How to obtain reliable estimates? • Methods for Model Comparison • How to compare the relative performance among competing models?
Metrics for Performance Evaluation • Focus on the predictive capability of a model • Rather than how fast it takes to classify or build models, scalability, etc. • Confusion Matrix: a: TP (true positive) b: FN (false negative) c: FP (false positive) d: TN (true negative)
Metrics for Performance Evaluation… • Most widely-used metric:
Limitation of Accuracy • Consider a 2-class problem • Number of Class 0 examples = 9990 • Number of Class 1 examples = 10 • If model predicts everything to be class 0, accuracy is 9990/10000 = 99.9 % • Accuracy is misleading because model does not detect any class 1 example
Cost Matrix C(i|j): Cost of misclassifying class j example as class i
Cost-Sensitive Measures • Precision is biased towards C(Yes|Yes) & C(Yes|No) • Recall is biased towards C(Yes|Yes) & C(No|Yes) • F-measure is biased towards all except C(No|No)
Model Evaluation • Metrics for Performance Evaluation • How to evaluate the performance of a model? • Methods for Performance Evaluation • How to obtain reliable estimates? • Methods for Model Comparison • How to compare the relative performance among competing models?
Methods for Performance Evaluation • How to obtain a reliable estimate of performance? • Performance of a model may depend on other factors besides the learning algorithm: • Class distribution • Cost of misclassification • Size of training and test sets
Learning Curve • Learning curve shows how accuracy changes with varying sample size • Requires a sampling schedule for creating learning curve: • Arithmetic sampling(Langley, et al) • Geometric sampling(Provost et al) Effect of small sample size: • Bias in the estimate • Variance of estimate
Methods of Estimation • Holdout • Reserve 2/3 for training and 1/3 for testing • Random subsampling • Repeated holdout • Cross validation • Partition data into k disjoint subsets • k-fold: train on k-1 partitions, test on the remaining one • Leave-one-out: k=n • Stratified sampling • oversampling vs undersampling • Bootstrap • Sampling with replacement
Model Evaluation • Metrics for Performance Evaluation • How to evaluate the performance of a model? • Methods for Performance Evaluation • How to obtain reliable estimates? • Methods for Model Comparison • How to compare the relative performance among competing models?
ROC (Receiver Operating Characteristic) • Characterize the trade-off between positive hits and false alarms • ROC curve plots TP (on the y-axis) against FP (on the x-axis) • Performance of each classifier represented as a point on the ROC curve • changing the threshold of algorithm, sample distribution or cost matrix changes the location of the point
At threshold t: TP=0.5, FN=0.5, FP=0.12, FN=0.88 ROC Curve - 1-dimensional data set containing 2 classes (positive and negative) - any points located at x > t is classified as positive
ROC Curve (TP,FP): • (0,0): declare everything to be negative class • (1,1): declare everything to be positive class • (1,0): ideal • Diagonal line: • Random guessing • Below diagonal line: • prediction is opposite of the true class
Using ROC for Model Comparison • No model consistently outperform the other • M1 is better for small FPR • M2 is better for large FPR • Area Under the ROC curve • Ideal: • Area = 1 • Random guess: • Area = 0.5