Superclasses: CompactClassificationSVM
Support vector machine for binary classification
ClassificationSVM
is a support vector machine classifier for
one or twoclass learning. To train a ClassificationSVM
classifier,
use fitcsvm
.
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
an SVM classifier (Mdl
= fitcsvm(Tbl
,ResponseVarName
)Mdl
) trained using the sample
data contained in the table Tbl
. ResponseVarName
is
the name of the variable in Tbl
that contains
the class labels for one or twoclass classification. For details,
see fitcsvm
.
returns
an SVM classifer trained using the predictor data and class labels
in the table Mdl
= fitcsvm(Tbl
,formula
)Tbl
. formula
is
an explanatory model of the response and a subset of predictor variables
in Tbl
used for training. For details, see fitcsvm
.
returns
an SVM classifer trained using the predictor variables in table Mdl
= fitcsvm(Tbl
,Y
)Tbl
and
class labels in vector Y
. For details, see fitcsvm
.
returns
an SVM classifier trained using the predictors in the matrix Mdl
=
fitcsvm(X
,Y
)X
and
class labels in the vector Y
for one or twoclass
classification. For details, see fitcsvm
.
returns
a trained SVM classifier with additional options specified by one
or more Mdl
= fitcsvm(___,Name,Value)Name,Value
pair arguments, using any of
the previous syntaxes. For example, you can specify the type of cross
validation, the cost for misclassification, or the type of score transformation
function. For namevalue pair argument details, see fitcsvm
.
If you set one of the following five options, then Mdl
is
a ClassificationPartitionedModel
model: 'CrossVal'
, 'CVPartition'
, 'Holdout'
, 'KFold'
,
or 'Leaveout'
. Otherwise, Mdl
is
a ClassificationSVM
classifier.

sby1 numeric vector of trained classifier
coefficients from the dual problem, that is, the estimated Lagrange
multipliers. s is the number of support vectors
in the trained classifier, that is, If you specify removing duplicates using  

Numeric vector of linear predictor coefficients. If your predictor data contains categorical variables, then
the software uses full dummy encoding for these variables. The software
creates one dummy variable for each level of each categorical variable. If $$f\left(x\right)=\left(x/s\right)\prime \beta +b.$$ Mdl stores β, b,
and s in the properties Beta , Bias ,
and KernelParameters.Scale , respectively.
If  

Scalar corresponding to the trained classifier bias term.  

nby1 numeric vector of box constraints. n is
the number of observations in the training data (see the If you specify removing duplicates using  

Structure array containing:
 

Indices of categorical
predictors, stored as a vector of positive integers.  

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.  

Expanded predictor names, stored as a cell array of character vectors. If the model uses encoding for categorical variables, then  

Numeric vector of training data gradient values.  

Description of the crossvalidation optimization of hyperparameters,
stored as a
 

nby1 logical vector indicating whether
a corresponding row in the predictor data matrix is a support vector. n is
the number of observations in the training data (see If you specify removing duplicates using  

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 If your predictor data contains categorical variables, then
the software uses full dummy encoding for these variables. The software
creates one dummy variable for each level of each categorical variable. If  

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 character vectors containing the predictor names, in the order that they appear in the training data.  

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.  

Character vector describing the response variable  

Character vector 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 If your predictor data contains categorical variables, then
the software uses full dummy encoding for these variables. The software
creates one dummy variable for each level of each categorical variable. If  

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

sbyp numeric matrix
containing rows of If you specify If you specify removing duplicates using  

sby1 numeric vector of support vector class
labels. s is the number of support vectors in the
trained classifier, that is, A value of If you specify removing duplicates using  

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 character vectors representing the observed class labels
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 using support vector machine classification model 
Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).
For the mathematical formulation of the SVM binary classification algorithm, see Support Vector Machines for Binary Classification and Understanding Support Vector Machines.
NaN
, <undefined>
,
and empty character vector (''
) values indicate
missing values. fitcsvm
removes entire rows of
data corresponding to a missing response. When computing total weights
(see the next bullets), fitcsvm
ignores any weight
corresponding to an observation with at least one missing predictor. This
action can lead to unbalanced prior probabilities in balancedclass
problems. Consequently, observation box constraints might not equal BoxConstraint
.
fitcsvm
removes observations that
have zero weight or prior probability.
For twoclass learning, if you specify the cost matrix $$\mathcal{C}$$ (see Cost
),
then the software updates the class prior probabilities p (see Prior
)
to p_{c} by incorporating the
penalties described in $$\mathcal{C}$$.
Specifically, fitcsvm
:
Computes $${p}_{c}^{\ast}=p\prime \mathcal{C}.$$
Normalizes p_{c}^{*} so that the updated prior probabilities sum 1:
$${p}_{c}=\frac{1}{{\displaystyle \sum _{j=1}^{K}{p}_{c,j}^{\ast}}}{p}_{c}^{\ast}.$$
Resets the cost matrix to the default:
$$\mathcal{C}=\left[\begin{array}{cc}0& 1\\ 1& 0\end{array}\right].$$
Removes observations from the training data corresponding to classes with zero prior probability.
For twoclass learning, fitcsvm
normalizes
all observation weights (see Weights
) to sum
to 1. Then, renormalizes the normalized weights to sum up to the updated,
prior probability of the class to which the observation belongs. That
is, the total weight for observation j in class k is
$${w}_{j}^{\ast}=\frac{{w}_{j}}{{\displaystyle \sum _{\forall j\in \text{Class}k}{w}_{j}}}{p}_{c,k}.$$
For twoclass learning, fitcsvm
assigns
a box constraint to each observation in the training data. The formula
for the box constraint of observation j is
$${C}_{j}=n{C}_{0}{w}_{j}^{\ast}.$$
BoxConstraint
),
and $${w}_{j}^{\ast}$$ is
the total weight of observation j (see previous bullet).If you set 'Standardize',true
and
any of 'Cost'
, 'Prior'
, or 'Weights'
,
then fitcsvm
standardizes the predictors using
their corresponding weighted means and weighted standard deviations.
That is, fitcsvm
standardizes predictor j (x_{j})
using
$${x}_{j}^{\ast}=\frac{{x}_{j}{\mu}_{j}^{\ast}}{{\sigma}_{j}^{\ast}}.$$
$${\mu}_{j}^{\ast}=\frac{1}{{\displaystyle \sum _{k}{w}_{k}^{\ast}}}{\displaystyle \sum _{k}{w}_{k}^{\ast}{x}_{jk}}.$$
x_{jk} is observation k (row) of predictor j (column).
$${\left({\sigma}_{j}^{\ast}\right)}^{2}=\frac{{v}_{1}}{{v}_{1}^{2}{v}_{2}}{\displaystyle \sum _{k}{w}_{k}^{\ast}{\left({x}_{jk}{\mu}_{j}^{\ast}\right)}^{2}}.$$
$${v}_{1}={\displaystyle \sum _{j}{w}_{j}^{\ast}}.$$
$${v}_{2}={\displaystyle \sum _{j}{\left({w}_{j}^{\ast}\right)}^{2}}.$$
Let p
be the proportion of outliers
that you expect in the training data. If you set 'OutlierFraction',p
,
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.
If your predictor data contains categorical variables, then the software generally uses full dummy encoding for these variables. The software creates one dummy variable for each level of each categorical variable.
The PredictorNames
property stores
one element for each of the original predictor variable names. For
example, assume that there are three predictors, one of which is a
categorical variable with three levels. Then PredictorNames
is
a 1by3 cell array of character vectors containing the original names
of the predictor variables.
The ExpandedPredictorNames
property
stores one element for each of the predictor variables, including
the dummy variables. For example, assume that there are three predictors,
one of which is a categorical variable with three levels. Then ExpandedPredictorNames
is
a 1by5 cell array of character vectors containing the names of the
predictor variables and the new dummy variables.
Similarly, the Beta
property stores
one beta coefficient for each predictor, including the dummy variables.
The SupportVectors
property stores
the predictor values for the support vectors, including the dummy
variables. For example, assume that there are m support
vectors and three predictors, one of which is a categorical variable
with three levels. Then SupportVectors
is an nby5
matrix.
The X
property stores the training
data as originally input. It does not include the dummy variables.
When the input is a table, X
contains only the
columns used as predictors.
For predictors specified in a table, if any of the variables contain ordered (ordinal) categories, the software uses ordinal encoding for these variables.
For a variable having k ordered levels, the software creates k – 1 dummy variables. The jth dummy variable is 1 for levels up to j, and +1 for levels j + 1 through k.
The names of the dummy variables stored in the ExpandedPredictorNames
property
indicate the first level with the value +1.
The software stores k – 1 additional
predictor names for the dummy variables, including the names of levels
2, 3, ..., k.
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 .$$
[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.