Superclasses: CompactClassificationSVM
Support vector machine for binary classification
ClassificationSVM
is a support vector machine classifier for
one or twoclass learning. Use fitcsvm
and
the training data to train a ClassificationSVM
classifier.
Trained ClassificationSVM
classifiers store
the training data, parameter values, prior probabilities, support
vectors, and algorithmic implementation information. You can use these
classifiers to:
Estimate resubstitution predictions. For details,
see resubPredict
.
Predict labels or posterior probabilities for new
data. For details, see predict
.
returns
a trained SVM classifier (SVMModel
=
fitcsvm(X
,Y
)SVMModel
) based on the
input variables (also known as predictors, features, or attributes) X
and
output variables (also known as responses or class labels) Y
.
For details, see fitcsvm
.
returns
a trained SVM classifier with additional options specified by one
or more SVMModel
= fitcsvm(X
,Y
,Name,Value
)Name,Value
pair arguments. For namevalue
pair argument details, see fitcsvm
.
If you set one of the following five options, then SVMModel
is
a ClassificationPartitionedModel
model: 'CrossVal'
, 'CVPartition'
, 'Holdout'
, 'KFold'
,
or 'Leaveout'
. Otherwise, SVMModel
is
a ClassificationSVM
classifier.

Numeric vector of trained classifier coefficients from the dual
problem (i.e., the estimated Lagrange multipliers).  

Numeric vector of linear predictor coefficients. If $$f\left(x\right)=\left(x/s\right)\prime \beta +b.$$
If  

Scalar corresponding to the trained classifier bias term.  

Numeric vector of box constraints.
 

Structure array containing:
 

List of categorical predictors, which is always empty (  

List of elements in  

Structure array containing convergence information.
 

Square matrix, where During training, the software updates the prior probabilities by incorporating the penalties described in the cost matrix. Therefore,
This property is readonly. For more details, see Algorithms.  

Numeric vector of training data gradient values.  

Logical vector indicating whether a corresponding row in the
predictor data matrix is a support vector.  

Structure array containing the kernel name and parameter values. To display the values of The software accepts  

Object containing parameter values, e.g., the namevalue pair
argument values, used to train the SVM classifier. Access fields of  

Numeric vector of predictor means. If you specify  

Positive integer indicating the number of iterations required by the optimization routine to attain convergence. To set a limit on the number of iterations to, e.g.,  

Positive scalar representing the ν parameter for oneclass learning.  

Numeric scalar representing the number
of observations in the training data. If the input arguments  

Scalar indicating the expected proportion of outliers in the training data.  

Cell array of strings containing the predictor names, in the
order that they appear in  

Numeric vector of prior probabilities for each class. The order
of the elements of For twoclass learning, if you specify a cost matrix, then the software updates the prior probabilities by incorporating the penalties described in the cost matrix. This property is readonly. For more details, see Algorithms.  

String describing the response variable  

String representing a builtin transformation function, or a function handle for transforming predicted classification scores. To change the score transformation function to, e.g.,
 

Nonnegative integer indicating the shrinkage period, i.e., number of iterations between reductions of the active set. To set the shrinkage period to, e.g.,  

Numeric vector of predictor standard deviations. If you specify  

String indicating the solving routine that the software used to train the SVM classifier. To set the solver to, e.g.,  

Matrix containing rows of If you specify  

Numeric vector of support vector class labels.
 

Numeric vector of observation weights that the software used to train the SVM classifier. The length of
 

Numeric matrix of unstandardized predictor values that the software used to train the SVM classifier. Each row of The software excludes predictor data rows removed due to  

Categorical or character array, logical or numeric vector, or
cell array of strings representing the observed class labels that
the software used to train the SVM classifier. Each row of The software excludes elements removed due to 
compact  Compact support vector machine classifier 
crossval  Crossvalidated support vector machine classifier 
fitPosterior  Fit posterior probabilities 
resubEdge  Classification edge for support vector machine classifiers by resubstitution 
resubLoss  Classification loss for support vector machine classifiers by resubstitution 
resubMargin  Classification margins for support vector machine classifiers by resubstitution 
resubPredict  Predict support vector machine classifier resubstitution responses 
resume  Resume training support vector machine classifier 
compareHoldout  Compare accuracies of two classification models using new data 
discardSupportVectors  Discard support vectors for linear support vector machine models 
edge  Classification edge for support vector machine classifiers 
fitPosterior  Fit posterior probabilities 
loss  Classification error for support vector machine classifiers 
margin  Classification margins for support vector machine classifiers 
predict  Predict labels for support vector machine classifiers 
A parameter that controls the maximum penalty imposed on marginviolating observations, and aids in preventing overfitting (regularization).
If you increase the box constraint, then the SVM classifier assigns fewer support vectors. However, increasing the box constraint can lead to longer training times.
The Gram matrix of a set of n vectors {x_{1},..,x_{n}; x_{j} ∊ R^{p}} is an nbyn matrix with element (j,k) defined as G(x_{j},x_{k}) = <ϕ(x_{j}),ϕ(x_{k})>, an inner product of the transformed predictors using the kernel function ϕ.
For nonlinear SVM, the algorithm forms a Gram matrix using the predictor matrix columns. The dual formalization replaces the inner product of the predictors with corresponding elements of the resulting Gram matrix (called the "kernel trick"). Subsequently, nonlinear SVM operates in the transformed predictor space to find a separating hyperplane.
KKT complementarity conditions are optimization constraints required for optimal nonlinear programming solutions.
In SVM, the KKT complementarity conditions are
$$\{\begin{array}{l}{\alpha}_{j}\left[{y}_{j}\left(w\prime \varphi \left({x}_{j}\right)+b\right)1+{\xi}_{j}\right]=0\\ {\xi}_{j}\left(C{\alpha}_{j}\right)=0\end{array}$$
for all j = 1,...,n, where w_{j} is a weight, ϕ is a kernel function (see Gram matrix), and ξ_{j} is a slack variable. If the classes are perfectly separable, then ξ_{j} = 0 for all j = 1,...,n.
Oneclass learning, or unsupervised SVM, aims at separating data from the origin in the highdimensional, predictor space (not the original predictor space), and is an algorithm used for outlier detection.
The algorithm resembles that of SVM for binary classification. The objective is to minimize dual expression
$$0.5{\displaystyle \sum _{jk}{\alpha}_{j}}{\alpha}_{k}G({x}_{j},{x}_{k})$$
with respect to $${\alpha}_{1},\mathrm{...},{\alpha}_{n}$$, subject to
$$\sum {\alpha}_{j}}=n\nu $$
and $$0\le {\alpha}_{j}\le 1$$ for all j = 1,...,n. G(x_{j},x_{k},) is element (j,k) of the Gram matrix.
A small value of ν leads to fewer support vectors, and, therefore, a smooth, crude decision boundary. A large value of ν leads to more support vectors, and therefore, a curvy, flexible decision boundary. The optimal value of ν should be large enough to capture the data complexity and small enough to avoid overtraining. Also, 0 < ν ≤ 1.
For more details, see [5].
Support vectors are observations corresponding to strictly positive estimates of α_{1},...,α_{n}.
SVM classifiers that yield fewer support vectors for a given training set are more desirable.
The SVM binary classification algorithm searches for an optimal hyperplane that separates the data into two classes. For separable classes, the optimal hyperplane maximizes a margin (space that does not contain any observations) surrounding itself, which creates boundaries for the positive and negative classes. For inseparable classes, the objective is the same, but the algorithm imposes a penalty on the length of the margin for every observation that is on the wrong side of its class boundary.
The linear SVM score function is
$$f(x)=x\prime \beta +{\beta}_{0},$$
where:
x is an observation (corresponding
to a row of X
).
The vector β contains the
coefficients that define an orthogonal vector to the hyperplane (corresponding
to SVMModel.Beta
). For separable data, the optimal
margin length is $$2/\Vert \beta \Vert .$$
β_{0} is
the bias term (corresponding to SVMModel.Bias
).
The root of f(x) for particular coefficients defines a hyperplane. For a particular hyperplane, f(z) is the distance from point z to the hyperplane.
An SVM classifier searches for the maximum margin length, while keeping observations in the positive (y = 1) and negative (y = –1) classes separate. Therefore:
For separable classes, the objective is to minimize $$\Vert \beta \Vert $$ with respect to the β and β_{0} subject to y_{j}f(x_{j}) ≥ 1, for all j = 1,..,n. This is the primal formalization for separable classes.
For inseparable classes, SVM uses slack variables (ξ_{j}) to penalize the objective function for observations that cross the margin boundary for their class. ξ_{j} = 0 for observations that do not cross the margin boundary for their class, otherwise ξ_{j} ≥ 0.
The objective is to minimize$$0.5{\Vert \beta \Vert}^{2}+C{\displaystyle \sum {\xi}_{j}}$$ with respect to the β, β_{0}, and ξ_{j} subject to $${y}_{j}f({x}_{j})\ge 1{\xi}_{j}$$ and $${\xi}_{j}\ge 0$$ for all j = 1,..,n, and for a positive scalar box constraint C. This is the primal formalization for inseparable classes.
SVM uses the Lagrange multipliers method to optimize the objective.
This introduces n coefficients α_{1},...,α_{n}
(corresponding to SVMModel.Alpha
). The dual formalizations
for linear SVM are:
For separable classes, minimize
$$0.5{\displaystyle \sum _{j=1}^{n}{\displaystyle \sum}_{k=1}^{n}}{\alpha}_{j}{\alpha}_{k}{y}_{j}{y}_{k}{x}_{j}\prime {x}_{k}{\displaystyle \sum}_{j=1}^{n}{\alpha}_{j}$$
with respect to α_{1},...,α_{n}, subject to $$\sum {\alpha}_{j}}{y}_{j}=0$$, α_{j} ≥ 0 for all j = 1,...,n, and KarushKuhnTucker (KKT) complementarity conditions.
For inseparable classes, the objective is the same as for separable classes, except for the additional condition $$0\le {\alpha}_{j}\le C$$ for all j = 1,..,n.
The resulting score function is
$$f(x)={\displaystyle \sum _{j=1}^{n}{\widehat{\alpha}}_{j}}{y}_{j}x\prime {x}_{j}+\widehat{b}.$$
The score function is free of the estimate of β as a result of the primal formalization.
In some cases, there is a nonlinear boundary separating the classes. Nonlinear SVM works in a transformed predictor space to find an optimal, separating hyperplane.
The dual formalization for nonlinear SVM is
$$0.5{\displaystyle \sum _{j=1}^{n}{\displaystyle \sum _{k=1}^{n}{\alpha}_{j}}}{\alpha}_{k}{y}_{j}{y}_{k}G({x}_{j},{x}_{k}){\displaystyle \sum _{j=1}^{n}{\alpha}_{j}}$$
with respect to α_{1},...,α_{n}, subject to $$\sum {\alpha}_{j}}{y}_{j}=0$$, $$0\le {\alpha}_{j}\le C$$ for all j = 1,..,n, and the KKT complementarity conditions.G(x_{k},x_{j}) are elements of the Gram matrix. The resulting score function is
$$f(x)={\displaystyle \sum _{j=1}^{n}{\alpha}_{j}}{y}_{j}G(x,{x}_{j})+b.$$
For more details, see Understanding Support Vector Machines, [1], and [3].
Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB documentation.
All solvers implement L1 softmargin minimization.
fitcsvm
and svmtrain
use,
among other algorithms, SMO for optimization. The software implements
SMO differently between the two functions, but numerical studies show
that there is sensible agreement in the results.
For oneclass learning, the software estimates the Lagrange multipliers, α_{1},...,α_{n}, such that
$$\sum _{j=1}^{n}{\alpha}_{j}}=n\nu .$$
For twoclass learning, if you specify a cost matrix C, then the software updates the class prior probabilities (p) to p_{c} by incorporating the penalties described in C. The formula for the updated prior probability vector is
$${p}_{c}=\frac{p\prime C}{\sum p\prime C}.$$
Subsequently, the software resets the cost matrix to the default:
$$C=\left[\begin{array}{cc}0& 1\\ 1& 0\end{array}\right].$$
If you set 'Standardize',true
when
you train the SVM classifier using fitcsvm
,
then the software trains the classifier using the standardized predictor
matrix, but stores the unstandardized data in the classifier property X
.
However, if you standardize the data, then the data size in memory
doubles until optimization ends.
If you set 'Standardize',true
and
any of 'Cost'
, 'Prior'
, or 'Weights'
,
then the software standardizes the predictors using their corresponding
weighted means and weighted standard deviations.
Let p
be the proportion of outliers
you expect in the training data. If you use 'OutlierFraction',p
when
you train the SVM classifier using fitcsvm
, then:
For oneclass learning, the software trains the bias
term such that 100p
% of the observations in the
training data have negative scores.
The software implements robust learning for
twoclass learning. In other words, the software attempts to remove
100p
% of the observations when the optimization
algorithm converges. The removed observations correspond to gradients
that are large in magnitude.
[1] Hastie, T., R. Tibshirani, and J. Friedman. The Elements of Statistical Learning, Second Edition. NY: Springer, 2008.
[2] Scholkopf, B., J. C. Platt, J. C. ShaweTaylor, A. J. Smola, and R. C. Williamson. "Estimating the Support of a HighDimensional Distribution." Neural Comput., Vol. 13, Number 7, 2001, pp. 1443–1471.
[3] Christianini, N., and J. C. ShaweTaylor. An Introduction to Support Vector Machines and Other KernelBased Learning Methods. Cambridge, UK: Cambridge University Press, 2000.
[4] Scholkopf, B. and A. Smola. Learning with Kernels: Support Vector Machines, Regularization, Optimization and Beyond, Adaptive Computation and Machine Learning Cambridge, MA: The MIT Press, 2002.