Support vector machine (SVM) for one-class and binary classification
ClassificationSVM
is a support vector machine (SVM) classifier for one-class and two-class learning. Trained ClassificationSVM
classifiers store training data, parameter values, prior probabilities, support vectors, and algorithmic implementation information. Use these classifiers to perform tasks such as fitting a score-to-posterior-probability transformation function (see fitPosterior
) and predicting labels for new data (see predict
).
Create a ClassificationSVM
object by using fitcsvm
.
compact | Reduce size of support vector machine (SVM) classifier |
compareHoldout | Compare accuracies of two classification models using new data |
crossval | Cross-validate support vector machine (SVM) classifier |
discardSupportVectors | Discard support vectors for linear support vector machine (SVM) classifier |
edge | Find classification edge for support vector machine (SVM) classifier |
fitPosterior | Fit posterior probabilities for support vector machine (SVM) classifier |
incrementalLearner | Convert binary classification support vector machine (SVM) model to incremental learner |
loss | Find classification error for support vector machine (SVM) classifier |
margin | Find classification margins for support vector machine (SVM) classifier |
partialDependence | Compute partial dependence |
plotPartialDependence | Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots |
predict | Classify observations using support vector machine (SVM) classifier |
resubEdge | Find classification edge for support vector machine (SVM) classifier by resubstitution |
resubLoss | Find classification loss for support vector machine (SVM) classifier by resubstitution |
resubMargin | Find classification margins for support vector machine (SVM) classifier by resubstitution |
resubPredict | Classify observations in support vector machine (SVM) classifier |
resume | Resume training support vector machine (SVM) classifier |
For the mathematical formulation of the SVM binary classification algorithm, see Support Vector Machines for Binary Classification and Understanding Support Vector Machines.
NaN
, <undefined>
, empty character vector
(''
), empty string (""
), and
<missing>
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 balanced-class problems. Consequently, observation box constraints might not equal
BoxConstraint
.
fitcsvm
removes observations that
have zero weight or prior probability.
For two-class learning, if you specify the cost matrix (see Cost
),
then the software updates the class prior probabilities p (see Prior
)
to pc by incorporating the
penalties described in .
Specifically, fitcsvm
completes these steps:
Compute
Normalize pc* so that the updated prior probabilities sum to 1.
K is the number of classes.
Reset the cost matrix to the default
Remove observations from the training data corresponding to classes with zero prior probability.
For two-class learning, fitcsvm
normalizes all observation weights (see
Weights
) to sum to 1. The function 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
wj is the normalized weight for observation j; pc,k is the updated prior probability of class k (see previous bullet).
For two-class learning, fitcsvm
assigns a box constraint to each
observation in the training data. The formula for the box constraint of observation
j is
n is the training sample size,
C0 is the initial box constraint (see the
'BoxConstraint'
name-value pair argument), and is the total weight of observation j (see previous
bullet).
If you set 'Standardize',true
and the 'Cost'
,
'Prior'
, or 'Weights'
name-value pair
argument, then fitcsvm
standardizes the predictors using their
corresponding weighted means and weighted standard deviations. That is,
fitcsvm
standardizes predictor j
(xj) using
xjk is observation k (row) of predictor j (column).
Assume that p
is the proportion of outliers that you expect in the training
data, and that you set 'OutlierFraction',p
.
For one-class 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
two-class 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 1-by-3 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 1-by-5 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 n-by-5
matrix.
The X
property stores the training data as originally input
and 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 with 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 soft-margin minimization.
For one-class learning, the software estimates the Lagrange multipliers, α1,...,αn, such that
[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. Shawe-Taylor, A. J. Smola, and R. C. Williamson. “Estimating the Support of a High-Dimensional Distribution.” Neural Comput., Vol. 13, Number 7, 2001, pp. 1443–1471.
[3] Christianini, N., and J. C. Shawe-Taylor. An Introduction to Support Vector Machines and Other Kernel-Based 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.