ClassificationSVM Predict - Classify observations using support vector machine (SVM) classifier for one-class and
binary classification - Simulink ([original](http://www.mathworks.com/help/stats/classificationsvmpredict.html)) ([raw](?raw))
Classify observations using support vector machine (SVM) classifier for one-class and binary classification
Since R2020b
Libraries:
Statistics and Machine Learning Toolbox / Classification
Description
The ClassificationSVM Predict block classifies observations using an SVM classification object (ClassificationSVM or CompactClassificationSVM) for one-class and two-class (binary) classification.
Import a trained SVM classification object into the block by specifying the name of a workspace variable that contains the object. The input port x receives an observation (predictor data), and the output port label returns a predicted class label for the observation. You can add the optional output port score, which returns predicted class scores or posterior probabilities.
Examples
Ports
Input
Predictor data, specified as a column vector or row vector of one observation.
The variables in x must have the same order as the predictor variables that trained the SVM model specified by**Select trained machine learning model**.
If you set 'Standardize',true
in fitcsvm when training the SVM model, then the ClassificationSVM Predict block standardizes the values of x using the means and standard deviations in the Mu
andSigma
properties (respectively) of the SVM model.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Output
Predicted class label, returned as a scalar.
- For one-class learning, label is the value representing the positive class.
- For two-class learning, label is the class yielding the largest score or the largest posterior probability.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Predicted class scores or posterior probabilities, returned as a scalar for one-class learning or a 1-by-2 vector for two-class learning.
- For one-class learning, score is the classification score of the positive class. You cannot obtain posterior probabilities for one-class learning.
- For two-class learning, score is a 1-by-2 vector.
- The first and second element ofscore correspond to the classification scores of the negative class (
svmMdl.ClassNames(1)
) and the positive class (svmMdl.ClassNames(2)
), respectively, wheresvmMdl
is the SVM model specified by Select trained machine learning model. You can use theClassNames
property ofsvmMdl
to check the negative and positive class names. - If you fit the optimal score-to-posterior-probability transformation function using fitPosterior or fitSVMPosterior, thenscore contains class posterior probabilities. Otherwise,score contains class scores.
- The first and second element ofscore correspond to the classification scores of the negative class (
Dependencies
To enable this port, select the check box for Add output port for predicted class scores on theMain tab of the Block Parameters dialog box.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Parameters
Main
Data Types
Fixed-Point Operational Parameters
Data Type
Block Characteristics
Data Types | Boolean | double | enumerated | fixed point | half | integer | single |
---|---|---|---|---|---|---|
Direct Feedthrough | yes | |||||
Multidimensional Signals | no | |||||
Variable-Size Signals | no | |||||
Zero-Crossing Detection | no |
More About
The SVM classification score for classifying observation x is the signed distance from x to the decision boundary ranging from -∞ to +∞. A positive score for a class indicates that x is predicted to be in that class. A negative score indicates otherwise.
The positive class classification score f(x) is the trained SVM classification function. f(x) is also the numerical predicted response for x, or the score for predicting x into the positive class.
where (α1,...,αn,b) are the estimated SVM parameters, G(xj,x) is the dot product in the predictor space between x and the support vectors, and the sum includes the training set observations. The negative class classification score for x, or the score for predicting_x_ into the negative class, is –f(x).
If G(xj,x) = xj_′_x (the linear kernel), then the score function reduces to
s is the kernel scale and β is the vector of fitted linear coefficients.
For more details, see Understanding Support Vector Machines.
The posterior probability is the probability that an observation belongs in a particular class, given the data.
For SVM, the posterior probability is a function of the score_P_(s) that observation j is in class k = {-1,1}.
- For separable classes, the posterior probability is the step function
where:- sj is the score of observation j.
- +1 and –1 denote the positive and negative classes, respectively.
- π is the prior probability that an observation is in the positive class.
- For inseparable classes, the posterior probability is the sigmoid function
where the parameters A and_B_ are the slope and intercept parameters, respectively.
The prior probability of a class is the assumed relative frequency with which observations from that class occur in a population.
The data types of internal model parameters are synchronized to the data type of the enabled score
output port. If thescore
output port is not enabled, the model parameter data types are synchronized to other internal data types.
Tips
- If you are using a linear SVM model and it has many support vectors, then prediction (classifying observations) can be slow. To efficiently classify observations based on a linear SVM model, remove the support vectors from the
ClassificationSVM
orCompactClassificationSVM
object by using discardSupportVectors.
Alternative Functionality
You can use a MATLAB Function block with the predict object function of an SVM classification object (ClassificationSVM or CompactClassificationSVM). For an example, see Predict Class Labels Using MATLAB Function Block.
When deciding whether to use the ClassificationSVM Predict block in the Statistics and Machine Learning Toolbox™ library or a MATLAB Function block with the predict
function, consider the following:
- If you use the Statistics and Machine Learning Toolbox library block, you can use the Fixed-Point Tool (Fixed-Point Designer) to convert a floating-point model to fixed point.
- Support for variable-size arrays must be enabled for a MATLAB Function block with the
predict
function. - If you use a MATLAB Function block, you can use MATLAB functions for preprocessing or post-processing before or after predictions in the same MATLAB Function block.
Extended Capabilities
Version History
Introduced in R2020b
Starting in R2021a, the default data type value and the supported data types of theLabel data type parameter depend on the labels used in the model specified by Select trained machine learning model. The default value is Inherit: Inherit via back propagation
for numeric and logical labels, andInherit: auto
for nonnumeric labels.
If you specified Label data type as Inherit: Inherit via back propagation
for nonnumeric labels or Inherit: Inherit from 'Constant value'
, then change the value toInherit: auto
.
Starting in R2021a, the default value of the parameters Score data type and Raw score data type isInherit: auto
.
Starting in R2021a, the Kernel data type parameter does not support inherited options. You can specify Kernel data type as a supported data type name or data type object.
See Also
Blocks
- ClassificationTree Predict | ClassificationEnsemble Predict | ClassificationECOC Predict | RegressionSVM Predict