main content

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

  • classificationsvm predict block icon

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

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

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 of score correspond to the classification scores of the negative class (svmmdl.classnames(1)) and the positive class (svmmdl.classnames(2)), respectively, where svmmdl is the svm model specified by . you can use the classnames property of svmmdl 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

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, or cell). if you supply training data in a table, the predictors must be numeric (double or single). also, you cannot use the categoricalpredictors 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'

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 parameters

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'

specify whether overflows saturate or wrap.

actionrationaleimpact on overflowsexample

select this check box (on).

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 int8 (signed 8-bit integer) data type can represent is 127. any block operation result greater than this maximum value causes overflow of the 8-bit integer. with the check box selected, the block output saturates at 127. similarly, the block output saturates at a minimum output value of –128.

clear this check box (off).

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 int8 (signed 8-bit integer) data type can represent is 127. any block operation result greater than this maximum value causes overflow of the 8-bit integer. with the check box cleared, the software interprets the value causing the overflow as int8, which can produce an unintended result. for example, a block result of 130 (binary 1000 0010) expressed as int8 is –126.

programmatic use

block parameter: saturateonintegeroverflow
type: character vector
values: 'off' | 'on'
default: 'off'

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'
data type

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 is mymdl, and the class labels are class 1 and class 2. then, the corresponding label values are mymdl_enumlabels.class_1 and mymdl_enumlabels.class_2. the block converts the class labels to valid matlab identifiers by using the matlab.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)

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: '[]'

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: '[]'

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'

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: '[]'

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: '[]'

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'

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: '[]'

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: '[]'

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' valuedata type
'gaussian' or 'rbf'kernel data type specifies the data type of the squared distance d2=xs2 for the gaussian kernel g(x,s)=exp(d2), 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 g(x,s)=xs', 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 g(x,s)=(1 xs')p, 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'

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: '[]'

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

boolean | double | enumerated | fixed point | half | integer | single

direct feedthrough

yes

multidimensional signals

no

variable-size signals

no

zero-crossing detection

no

more about

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 or compactclassificationsvm 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 r2020b
网站地图