classify observations using support vector machine (svm) classifier for one-凯发k8网页登录
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.
ports
input
x — predictor data
row vector | column vector
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 .
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
and
sigma
properties (respectively) of the svm
model.
data types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| boolean
| fixed point
output
label — predicted class label
scalar
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
score — predicted class scores or posterior probabilities
scalar | 1-by-2 vector
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 of score 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 . 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 or , then score contains class posterior probabilities. otherwise, score contains class scores.
dependencies
to enable this port, select the check box for on the main 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
select trained machine learning model — svm classification model
svmmdl
(default) | classificationsvm
object | compactclassificationsvm
object
specify the name of a workspace variable that contains a classificationsvm
object or
compactclassificationsvm
object.
when you train the svm model by using fitcsvm
, the following
restrictions apply:
the predictor data cannot include categorical predictors (
logical
,categorical
,char
,string
, orcell
). if you supply training data in a table, the predictors must be numeric (double
orsingle
). also, you cannot use thecategoricalpredictors
name-value argument. to include categorical predictors in a model, preprocess them by using before fitting the model.the value of the
scoretransform
name-value argument cannot be'invlogit'
or an anonymous function. for a block that predicts posterior probabilities given new observations, pass a trained svm model to or .the value of the
kernelfunction
name-value argument must be'gaussian'
(same as'rbf'
, default for one-class learning),'linear'
(default for two-class learning), or'polynomial'
.
programmatic use
block parameter:
trainedlearner |
type: workspace variable |
values:
classificationsvm object |
compactclassificationsvm object |
default:
'svmmdl' |
add output port for predicted class scores — add second output port for predicted class scores
off
(default) | on
select the check box to include the second output port score in the classificationsvm predict block.
programmatic use
block parameter:
showoutputscore |
type: character vector |
values:
'off' | 'on' |
default:
'off' |
data types
fixed-point operational parametersinteger rounding mode — rounding mode for fixed-point operations
floor
(default) | ceiling
| convergent
| nearest
| round
| simplest
| zero
specify the rounding mode for fixed-point operations. for more information, see (fixed-point designer).
block parameters always round to the nearest representable value. to control the rounding of a block parameter, enter an expression into the mask field using a matlab® rounding function.
programmatic use
block parameter:
rndmeth |
type: character vector |
values:
'ceiling' | 'convergent' | 'floor' | 'nearest' | 'round' | 'simplest' |
'zero' |
default:
'floor' |
saturate on integer overflow — method of overflow action
off
(default) | on
specify whether overflows saturate or wrap.
action | rationale | impact on overflows | example |
---|---|---|---|
select this check box
( | your model has possible overflow, and you want explicit saturation protection in the generated code. | overflows saturate to either the minimum or maximum value that the data type can represent. | the maximum value that the |
clear this check box
( | you want to optimize efficiency of your generated code. you want to avoid overspecifying how a block handles out-of-range signals. for more information, see (simulink). | overflows wrap to the appropriate value that the data type can represent. | the maximum value that the |
programmatic use
block parameter:
saturateonintegeroverflow |
type: character vector |
values:
'off' | 'on' |
default:
'off' |
lock output data type setting against changes by the fixed-point tools — prevention of fixed-point tools from overriding data type
off
(default) | on
select this parameter to prevent the fixed-point tools from overriding the data type you specify for the block. for more information, see (fixed-point designer).
programmatic use
block parameter:
lockscale |
type: character vector |
values:
'off' | 'on' |
default:
'off' |
label data type — data type of label output
inherit: inherit via back propagation
| inherit: auto
| double
| single
| half
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| boolean
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
| enum:
|
specify the data type for the label output. the type can be
inherited, specified as an enumerated data type, or
expressed as a data type object such as simulink.numerictype
.
the supported data types depend on the labels used in the model specified by .
if the model uses numeric or logical labels, the supported data types are
inherit: inherit via back propagation
(default),double
,single
,half
,int8
,uint8
,int16
,uint16
,int32
,uint32
,int64
,uint64
,boolean
, fixed point, and a data type object.if the model uses nonnumeric labels, the supported data types are
inherit: auto
(default),enum:
, and a data type object.
when you select an inherited option, the software behaves as follows:
inherit: inherit via back propagation
(default for numeric and logical labels) — simulink® automatically determines the label data type of the block during data type propagation (see (simulink)). in this case, the block uses the data type of a downstream block or signal object.inherit: auto
(default for nonnumeric labels) — the block uses an autodefined enumerated data type variable. for example, suppose the workspace variable name specified by ismymdl
, and the class labels areclass 1
andclass 2
. then, the corresponding label values aremymdl_enumlabels.class_1
andmymdl_enumlabels.class_2
. the block converts the class labels to valid matlab identifiers by using thematlab.lang.makevalidname
function.
for more information about data types, see (simulink).
click the show data type assistant button to display the data type assistant, which helps you set the data type attributes. for more information, see (simulink).
programmatic use
block parameter:
labeldatatypestr |
type: character vector |
values: 'inherit: inherit via back
propagation' | 'inherit: auto' |
'double' | 'single' |
'half' | 'int8' |
'uint8' | 'int16' |
'uint16' | 'int32' |
'uint32' | 'int64' |
'uint64' | 'boolean' |
'fixdt(1,16)' | 'fixdt(1,16,0)' |
'fixdt(1,16,2^0,0)' | 'enum: | '' |
default: 'inherit: inherit via
back propagation' (for numeric and logical labels) |
'inherit: auto' (for nonnumeric labels) |
label minimum — minimum value of label output for range checking
[]
(default) | scalar
specify the lower value of the label output range that simulink checks.
simulink uses the minimum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as software-in-the-loop (sil) mode or external mode. for more information, see (embedded coder).
note
the label minimum parameter does not saturate or clip the actual label output signal. to do so, use the (simulink) block instead.
dependencies
you can specify this parameter only if the model specified by uses numeric labels.
programmatic use
block parameter:
labeloutmin |
type: character vector |
values: '[]' |
scalar |
default: '[]' |
label maximum — maximum value of label output for range checking
[]
(default) | scalar
specify the upper value of the label output range that simulink checks.
simulink uses the maximum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as sil or external mode. for more information, see (embedded coder).
note
the label maximum parameter does not saturate or clip the actual label output signal. to do so, use the (simulink) block instead.
dependencies
you can specify this parameter only if the model specified by uses numeric labels.
programmatic use
block parameter:
labeloutmax |
type: character vector |
values: '[]' |
scalar |
default: '[]' |
score data type — data type of score output
inherit: auto
(default) | double
| single
| half
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| boolean
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
|
specify the data type for the score output. the type can be
inherited, specified directly, or expressed as a data type object such as
simulink.numerictype
.
when you select inherit: auto
, the block uses a rule that
inherits a data
type.
for more information about data types, see (simulink).
click the show data type assistant button to display the data type assistant, which helps you set the data type attributes. for more information, see (simulink).
programmatic use
block parameter:
scoredatatypestr |
type: character vector |
values: 'inherit: auto'
| 'double' | 'single' |
'half' | 'int8' |
'uint8' | 'int16' |
'uint16' | 'int32' |
'uint32' | 'int64' |
'uint64' | 'boolean' |
'fixdt(1,16)' | 'fixdt(1,16,0)' |
'fixdt(1,16,2^0,0)' | '' |
default: 'inherit:
auto' |
score minimum — minimum value of score output for range checking
[]
(default) | scalar
specify the lower value of the score output range that simulink checks.
simulink uses the minimum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as software-in-the-loop (sil) mode or external mode. for more information, see (embedded coder).
note
the score minimum parameter does not saturate or clip the actual score signal. to do so, use the (simulink) block instead.
programmatic use
block parameter:
scoreoutmin |
type: character vector |
values: '[]' |
scalar |
default: '[]' |
score maximum — maximum value of score output for range checking
[]
(default) | scalar
specify the upper value of the score output range that simulink checks.
simulink uses the maximum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as sil or external mode. for more information, see (embedded coder).
note
the score maximum parameter does not saturate or clip the actual score signal. to do so, use the (simulink) block instead.
programmatic use
block parameter:
scoreoutmax |
type: character vector |
values: '[]' |
scalar |
default: '[]' |
raw score data type — untransformed score data type
inherit: auto
(default) | double
| single
| half
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| boolean
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
|
specify the data type for the internal untransformed scores. the type can be inherited, specified directly, or expressed as a data type object such as simulink.numerictype
.
when you select inherit: auto
, the block uses a rule that inherits a data type.
for more information about data types, see (simulink).
click the show data type assistant button to display the data type assistant, which helps you set the data type attributes. for more information, see (simulink).
dependencies
you can specify this parameter only if the model specified by uses a score transformation other than
'none'
(default, same as 'identity'
).
if the model uses no score transformations (
'none'
or'identity'
), then you can specify the score data type by using score data type.if the model uses a score transformation other than
'none'
or'identity'
, then you can specify the data type of untransformed raw scores by using this parameter. to specify the data type of transformed scores, use score data type.
you can change the score transformation option by specifying the
scoretransform
name-value argument during training, or by
changing the scoretransform
property after training.
programmatic use
block parameter: rawscoredatatypestr |
type: character vector |
values: 'inherit: auto' |
'double' | 'single' |
'half' | 'int8' |
'uint8' | 'int16' |
'uint16' | 'int32' |
'uint32' | 'int64' |
'uint64' | 'boolean' |
'fixdt(1,16)' | 'fixdt(1,16,0)' |
'fixdt(1,16,2^0,0)' | '' |
default: 'inherit: auto' |
raw score minimum — minimum untransformed score for range checking
[]
(default) | scalar
specify the lower value of the untransformed score range that simulink checks.
simulink uses the minimum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as software-in-the-loop (sil) mode or external mode. for more information, see (embedded coder).
note
the raw score minimum parameter does not saturate or clip the actual untransformed score signal.
programmatic use
block parameter: rawscoreoutmin |
type: character vector |
values: '[]' | scalar |
default: '[]' |
raw score maximum — maximum untransformed score for range checking
[]
(default) | scalar
specify the upper value of the untransformed score range that simulink checks.
simulink uses the maximum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as sil or external mode. for more information, see (embedded coder).
note
the raw score maximum parameter does not saturate or clip the actual untransformed score signal.
programmatic use
block parameter: rawscoreoutmax |
type: character vector |
values: '[]' | scalar |
default: '[]' |
kernel data type — kernel computation data type
double
(default) | single
| half
| int8
| uint8
| int16
| uint16
| int32
| int64
| uint64
| uint32
| boolean
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
|
specify the data type of a parameter for kernel computation. the type can be specified
directly or expressed as a data type object such as
simulink.numerictype
.
the kernel data type parameter specifies the data type of a
different parameter depending on the type of kernel function of the specified svm model.
you specify the kernelfunction
name-value argument when training the
svm model.
'kernelfunction' value | data type |
---|---|
'gaussian' or 'rbf' | kernel data type specifies the data type of the squared distance for the gaussian kernel , where x is the predictor data for an observation and s is a support vector. |
'linear' | kernel data type specifies the data type for the output of the linear kernel function , where x is the predictor data for an observation and s is a support vector. |
'polynomial' | kernel data type specifies the data type for the output of the polynomial kernel function , where x is the predictor data for an observation, s is a support vector, and p is a polynomial kernel function order. |
for more information about data types, see (simulink).
click the show data type assistant button to display the data type assistant, which helps you set the data type attributes. for more information, see (simulink).
programmatic use
block parameter:
kerneldatatypestr |
type: character vector |
values: 'double' |
'single' | 'half' |
'int8' | 'uint8' |
'int16' | 'uint16' |
'int32' | 'uint32' |
'uint64' | 'int64' |
'boolean' | 'fixdt(1,16)' |
'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)'
| '' |
default:
'double' |
kernel minimum — minimum kernel computation value for range checking
[]
(default) | scalar
specify the lower value of the kernel computation internal variable range that simulink checks.
simulink uses the minimum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as software-in-the-loop (sil) mode or external mode. for more information, see (embedded coder).
note
the kernel minimum parameter does not saturate or clip the actual kernel computation value signal.
programmatic use
block parameter:
kerneloutmin |
type: character vector |
values: '[]' |
scalar |
default: '[]' |
kernel maximum — maximum kernel computation value for range checking
[]
(default) | scalar
specify the upper value of the kernel computation internal variable range that simulink checks.
simulink uses the maximum value to perform:
parameter range checking for some blocks (see (simulink)).
simulation range checking (see (simulink) and (simulink)).
automatic scaling of fixed-point data types.
optimization of the code that you generate from the model. this optimization can remove algorithmic code and affect the results of some simulation modes, such as sil or external mode. for more information, see (embedded coder).
note
the kernel maximum parameter does not saturate or clip the actual kernel computation value signal.
programmatic use
block parameter:
kerneloutmax |
type: character vector |
values: '[]' |
scalar |
default: '[]' |
block characteristics
data types |
|
direct feedthrough |
|
multidimensional signals |
|
variable-size signals |
|
zero-crossing detection |
|
more about
classification score
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 is the trained svm classification function. is also the numerical predicted response for x, or the score for predicting x into the positive class.
where are the estimated svm parameters, 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 .
posterior probability
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.
prior probability
the prior probability of a class is the assumed relative frequency with which observations from that class occur in a population.
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 .
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 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
c/c code generation
generate c and c code using simulink® coder™.
fixed-point conversion
design and simulate fixed-point systems using fixed-point designer™.
version history
introduced in r2020br2021a: default value of label data type is inherit: inherit via
back propagation
for numeric and logical labels and
inherit: auto
for nonnumeric labels
starting in r2021a, the default data type value and the supported data types of the
label data type parameter depend on the labels used in the
model specified by . the default value is inherit:
inherit via back propagation
for numeric and logical labels, and
inherit: 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 to
inherit: auto
.
r2021a: default value of score data type and raw score data type is inherit: auto
starting in r2021a, the default value of the parameters score data
type and raw score data type is
inherit: auto
.
r2021a: specify kernel data type as a data type name or data type object
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
- | | |
objects
functions
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)