classificationSVMComponent
Pipeline component for one-class and binary classification using SVM classifier
Since R2026a
Description
classificationSVMComponent is a pipeline component that creates a support
vector machine (SVM) model for one-class and binary classification. The pipeline component
uses the functionality of the fitcsvm function during the learn phase to train
the SVM classification model. The component uses the functionality of the predict and loss functions during the run phase to perform
classification.
Creation
Description
creates a pipeline component for an SVM classification model.component = classificationSVMComponent
sets writable Properties using one or more
name-value arguments. For example, you can specify the kernel function, cost of
misclassification, and expected proportion of outliers.component = classificationSVMComponent(Name=Value)
Properties
Structural Parameters
The software sets structural parameters when you create the component. You cannot modify structural parameters after creating the component.
This property is read-only after the component is created.
Observation weights flag, specified as 0 (false)
or 1 (true). If UseWeights is
true, the component adds a third input "Weights" to the
Inputs component property, and a third input tag
3 to the InputTags component
property.
Example: c = classificationSVMComponent(UseWeights=1)
Data Types: logical
Learn Parameters
The software sets learn parameters when you create the component. You can modify learn
parameters using dot notation any time before you use the learn object
function. Any unset learn parameters use the corresponding default values.
Initial estimates of alpha coefficients, specified as a numeric vector of
nonnegative values. The length of Alpha must be equal to the
number of rows in the first data argument of learn.
Alpha cannot contain any NaN values.
By default, the component uses the value
0.5*ones(size(X,1),1) for one-class
learning, where X is the first data argument of
learn. The component uses the value
zeros(size(X,1),1) for binary
learning.
Example: c =
classificationSVMComponent(Alpha=0.1*ones(size(X,1),1))
Example: c.Alpha = 0.5*ones(size(X,1),1)
Data Types: single | double
Box constraint, specified as a positive scalar. The box constraint controls the maximum penalty imposed on margin-violating observations, which helps prevent overfitting.
For one-class learning, the component uses a box constraint of
1 for all observations in the first data argument of
learn. For binary learning, the component uses the
BoxConstraint value as the initial box constraint and assigns a
box constraint to each observation in the first data argument of
learn. The formula for the box constraint of observation
j is
where C0 is the initial
box constraint and
w*j is the
observation weight adjusted by Cost and
Prior for observation j.
Example: c =
classificationSVMComponent(BoxConstraint=100)
Example: c.BoxConstraint = 10
Data Types: single | double
Cache size, specified as "maximal" or a positive scalar.
If
CacheSizeis"maximal", the component reserves enough memory to hold the entire n-by-n Gram matrix.If
CacheSizeis a positive scalar, the component reservesCacheSizemegabytes of memory for training the model.
Example: c =
classificationSVMComponent(CacheSize="maximal")
Example: c.CacheSize = 2000
Data Types: single | double | char | string
Flag to clip the alpha coefficients, specified as 1
(true) or 0 (false).
If
ClipAlphasistrue, then at each optimization iteration, the component evaluates the alpha coefficients of the observations in the first data argument oflearn. If the alpha coefficient of any observation is near either0or the box constraint of that observation, the component sets the alpha coefficient of the observation to either0or the box constraint value, respectively.If
ClipAlphasisfalse, the component does not change the alpha coefficients during optimization.
The component stores the final alpha coefficient values in the
Alpha property of TrainedModel.
Example: c =
classificationSVMComponent(ClipAlphas=false)
Example: c.ClipAlphas = true
Data Types: logical
Misclassification cost, specified as a square matrix or a structure.
If
Costis a square matrix,Cost(i,j)is the cost of classifying a point into classjif its true class isi.If
Costis a structureS, it has two fields:S.ClassificationCosts, which contains the cost matrix; andS.ClassNames, which contains the group names and defines the class order of the rows and columns of the cost matrix.
Example: c = classificationSVMComponent(Cost=[0 1; 2
0])
Example: c.Cost = [0 2; 1 0]
Data Types: single | double | struct
Tolerance for the gradient difference between the upper and lower violators
obtained by the SMO or ISDA solver optimization routine, specified as a nonnegative
scalar. If the gradient difference between the current iteration and previous
iteration is less than DeltaGradientTolerance, the component
terminates optimization.
If DeltaGradientTolerance is 0, the
component does not use the tolerance for the gradient difference to check for
optimization convergence.
This property is valid only when Solver is
"SMO" or "ISDA". If
Solver is "SMO", the default value is
0. If Solver is "ISDA",
the default value is 1e-3.
Example: c =
classificationSVMComponent(DeltaGradientTolerance=1e-2)
Example: c.DeltaGradientTolerance = 0.1
Data Types: single | double
Feasibility gap tolerance obtained by the SMO or ISDA solver optimization routine, specified as a nonnegative scalar. After each iteration, the component calculates the feasibility gap using
where J(β) is the primal objective and L(α) is the dual objective.
If the feasibility gap is less than GapTolerance, the
component terminates optimization.
If GapTolerance is 0, the component does
not use the feasibility gap tolerance to check for optimization convergence.
This property is valid only when Solver is
"SMO" or "ISDA".
Example: c =
classificationSVMComponent(GapTolerance=1e-2)
Example: c.GapTolerance = 0.1
Data Types: single | double
Maximal number of optimization iterations, specified as a positive integer.
After the component executes IterationLimit iterations, it
updates TrainedModel with a trained SVM model, regardless of whether the
optimization routine successfully converges.
Example: c =
classificationSVMComponent(IterationLimit=1e8)
Example: c.IterationLimit = 1e7
Data Types: single | double
Kernel function used to compute the elements of the Gram matrix, specified as a
kernel function name. During optimization, the component uses the Gram matrix to
compute the inner products of each pair of observations in the feature space specified
by KernelFunction.
Assume
G(xj,xk)
is element (j,k) of the Gram matrix, where
xj and
xk are p-dimensional
vectors representing observations j and k in the
first data argument of learn. This table describes the built-in
kernel functions based on this assumption.
| Kernel Function Name | Description | Formula |
|---|---|---|
"gaussian" or "rbf" | Gaussian or Radial Basis Function (RBF) kernel, default for one-class learning |
|
"linear" | Linear kernel, default for two-class learning |
|
"polynomial" | Polynomial kernel. Use PolynomialOrder to specify the order, q, of
the polynomial kernel. |
|
To specify a custom kernel function, define a function that accepts two matrices
as inputs, U and V, and returns a Gram matrix of
the rows of U and V. The custom function must be
on the MATLAB path.
Example: c =
classificationSVMComponent(KernelFunction="gaussian")
Example: c.KernelFunction = "polynomial"
Data Types: char | string
Kernel scale parameter, specified as "auto" or a positive
scalar. The component divides all elements of the first data argument of
learn by the value of KernelScale. Then,
the component applies the appropriate kernel norm to compute the Gram matrix.
If KernelScale is "auto", the component
selects an appropriate scale factor using a heuristic procedure. This procedure uses
subsampling, so estimates can vary between component executions.
This argument is valid only when KernelFunction is a built-in function name. If you specify a custom
kernel function, you must apply scaling within the function.
Example: c =
classificationSVMComponent(KernelScale="auto")
Example: c.KernelScale = 0.1
Data Types: single | double | char | string
Kernel offset parameter, specified as a nonnegative scalar. The component adds
KernelOffset to each element in the Gram matrix.
This property is valid only when Solver is
"SMO" or "ISDA".
If Solver is "SMO", the default value is
0. If Solver is "ISDA",
the default value is 0.1.
Example: c =
classificationSVMComponent(KernelOffset=0)
Example: c.KernelOffset = 0.1
Data Types: single | double
Karush–Kuhn–Tucker (KKT) complementarity conditions violation tolerance, specified
as a nonnegative scalar. After each optimization iteration, the component evaluates
the KKT violation. If the largest violation is less than
KKTTolerance, the component terminates optimization. For more
information on KKT complementarity conditions, see Karush-Kuhn-Tucker (KKT) Complementarity Conditions.
If KKTTolerance is 0, the component does
not use the KKT complementarity conditions violation tolerance to check for
optimization convergence.
This property is valid only when Solver is
"SMO" or "ISDA". If
Solver is "SMO", the default value is
0. If Solver is "ISDA",
the default value is 1e-3.
Example: c =
classificationSVMComponent(KKTTolerance=1e-2)
Example: c.KKTTolerance = 1e-3
Data Types: single | double
ν parameter for one-class learning, specified as a positive
scalar in the range (0,1].
A small Nu value results in fewer support vectors and,
therefore, a smooth, crude decision boundary. A large Nu value
results in more support vectors and, therefore, a curvy, flexible decision boundary.
An optimal Nu value is large enough to capture data complexity,
yet small enough to prevent overfitting.
Example: c = classificationSVMComponent(Nu=0.25)
Example: c.Nu = 0.75
Data Types: single | double
Expected proportion of outliers in the training data, specified as a numeric
scalar in the interval [0,1).
For binary learning, the component attempts to remove the expected proportion of observations when the optimization algorithm converges. The removed observations correspond to gradients that are large in magnitude.
For one-class learning, the component finds an appropriate bias term such that the
proportion of the observations in OutlierFraction have negative
scores.
Example: c =
classificationSVMComponent(OutlierFraction=0.01)
Example: c.OutlierFraction = 0.1
Data Types: single | double
Polynomial kernel function order, specified as a positive integer.
This argument is valid only when KernelFunction is "polynomial".
Use PolynomialOrder to specify the order q
of the polynomial kernel function
where
G(xj,xk)
is element (j,k) of the Gram matrix, and
xj and
xk are p-dimensional
vectors representing observations j and k in the
first data argument of learn.
Example: c =
classificationSVMComponent(PolynomialOrder=2)
Example: c.PolynomialOrder = 3
Data Types: single | double
Prior probabilities for each class, specified as a value in this table.
| Value | Description |
|---|---|
"empirical" | The class prior probabilities are the class relative frequencies. The class relative
frequencies are determined by the second data argument of
learn. |
"uniform" | All class prior probabilities are equal to 1/K, where K is the number of classes. |
| numeric vector | A numeric vector with one value for each class. Each element is a class prior probability.
The component normalizes the elements such that they sum to
1. |
| structure | A structure
|
If you set UseWeights to true, the component
renormalizes the weights to add up to the value of the prior probability in
the respective class.
Example: c = classificationSVMComponent(Prior="uniform")
Example: c.Prior = "empirical"
Data Types: single | double | char | string | struct
Flag to replace duplicate observations with single observations, specified as
0 (false) or 1
(true).
If RemoveDuplicates is true, the component
replaces duplicate observations with a single observation of the same value. If you
enable UseWeights, the weight of the single observation is equal to the sum of
the weights of the corresponding removed duplicates.
Example: c =
classificationSVMComponent(RemoveDuplicates=true)
Example: c.RemoveDuplicates = false
Data Types: logical
Number of iterations between reductions of the active set of optimization constraints, specified as a nonnegative integer. Shrinking the active set speeds up optimization convergence.
If ShrinkagePeriod is 0, the component
does not shrink the active set.
Example: c =
classificationSVMComponent(ShrinkagePeriod=1000)
Example: c.ShrinkagePeriod = 5000
Data Types: single | double
Optimization routine, specified as a value in this table.
| Value | Description |
|---|---|
"ISDA" | Iterative Single Data Algorithm (see [2]) |
"L1QP" | Uses quadprog (Optimization Toolbox) to implement
L1 soft-margin minimization by quadratic programming.
This option requires an Optimization Toolbox™ license. For more details, see Quadratic Programming Definition (Optimization Toolbox). |
"SMO" | Sequential Minimal Optimization (see [1]) |
The default value is "ISDA" if you set OutlierFraction to a positive value for binary learning, and
"SMO" otherwise.
Example: c =
classificationSVMComponent(Solver="ISDA")
Example: c.Solver = "SMO"
Data Types: char | string
Flag to standardize the predictor data, specified as 0
(false) or 1 (true).
If Standardize is true, the component
centers and scales each predictor variable by its weighted mean and standard
deviation. The component does not standardize categorical predictors.
Example: c =
classificationSVMComponent(Standardize=true)
Example: c.Standardize = false
Data Types: logical
Run Parameters
The software sets run parameters when you create the component. You can modify the run parameters using dot notation at any time. Any unset run parameters use the corresponding default values.
Loss function, specified as a built-in loss function name or a function handle.
This table lists the available built-in loss functions.
| Value | Description |
|---|---|
"binodeviance" | Binomial deviance |
"classifcost" | Observed misclassification cost |
"classiferror" | Misclassified rate in decimal |
"exponential" | Exponential loss |
"hinge" | Hinge loss |
"logit" | Logistic loss |
"mincost" | Minimal expected misclassification cost (for classification scores that are posterior probabilities) |
"quadratic" | Quadratic loss |
To specify a custom loss function, use function handle notation. For more
information on custom loss functions, see LossFun.
Example: c =
classificationSVMComponent(LossFun="classifcost")
Example: c.LossFun = "hinge"
Data Types: char | string | function_handle
Score transformation, specified as a built-in function name or a function handle.
This table summarizes the available built-in score transform functions.
| Value | Description |
|---|---|
"doublelogit" | 1/(1 + e–2x) |
"invlogit" | log(x / (1 – x)) |
"ismax" | Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0 |
"logit" | 1/(1 + e–x) |
"none" or "identity" | x (no transformation) |
"sign" | –1 for x < 0 0 for x = 0 1 for x > 0 |
"symmetric" | 2x – 1 |
"symmetricismax" | Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1 |
"symmetriclogit" | 2/(1 + e–x) – 1 |
To specify a custom score transform function, use function handle notation. The function must accept a matrix containing the original scores and return a matrix of the same size containing the transformed scores.
Example: c = classificationSVMComponent(ScoreTransform="logit")
Example: c.ScoreTransform = "symmetric"
Data Types: char | string | function_handle
Component Properties
The software sets component properties when you create the component. You can modify the
component properties (excluding HasLearnables and
HasLearned) using dot notation at any time. You cannot modify the
HasLearnables and HasLearned properties
directly.
Component identifier, specified as a character vector or string scalar.
Example: c =
classificationSVMComponent(Name="SVM")
Example: c.Name = "SVMClassifier"
Data Types: char | string
Names of the input ports, specified as a character vector, string array, or cell
array of character vectors. If UseWeights is true, the component adds the input port
"Weights" to Inputs.
Example: c =
classificationSVMComponent(Inputs=["X","Y"])
Example: c.Inputs = ["In1","In2"]
Data Types: char | string | cell
Names of the output ports, specified as a character vector, string array, or cell array of character vectors.
Example: c =
classificationSVMComponent(Outputs=["Class","ClassScore","LossVal"])
Example: c.Outputs = ["X","Y","Z"]
Data Types: char | string | cell
Tags that enable the automatic connection of the component inputs with other
components or pipelines, specified as a nonnegative integer vector. If you specify
InputTags, the number of tags must match the number of inputs
in Inputs. If
UseWeights is true, the component adds a third input
tag to InputTags.
Example: c = classificationSVMComponent(InputTags=[1
0])
Example: c.InputTags = [0 1]
Data Types: single | double
Tags that enable the automatic connection of the component outputs with other
components or pipelines, specified as a nonnegative integer vector. If you specify
OutputTags, the number of tags must match the number of outputs
in Outputs.
Example: c = classificationSVMComponent(OutputTags=[1 0
4])
Example: c.OutputTags=[1 2 0]
Data Types: single | double
This property is read-only.
Indicator for learnables, returned as 1
(true). A value of 1 indicates that the
component contains Learnables.
Data Types: logical
This property is read-only.
Indicator showing the learning status of the component, returned as
0 (false) or 1
(true). A value of 1 indicates that the
learn object function has been applied to the component, and
the Learnables are nonempty.
Data Types: logical
Learnables
The software sets learnables when you use the learn object
function. You cannot modify learnables directly.
This property is read-only.
Trained model, returned as a CompactClassificationSVM model object.
Object Functions
learn | Initialize and evaluate pipeline or component |
run | Execute pipeline or component for inference after learning |
reset | Reset pipeline or component |
series | Connect components in series to create pipeline |
parallel | Connect components or pipelines in parallel to create pipeline |
view | View diagram of pipeline inputs, outputs, components, and connections |
Examples
Create a classificationSVMComponent pipeline component.
component = classificationSVMComponent
component =
classificationSVMComponent with properties:
Name: "ClassificationSVM"
Inputs: ["Predictors" "Response"]
InputTags: [1 2]
Outputs: ["Predictions" "Scores" "Loss"]
OutputTags: [1 0 0]
Learnables (HasLearned = false)
TrainedModel: []
Structural Parameters (locked)
UseWeights: 0
Show all parameters
component is a classificationSVMComponent object
that contains one learnable, TrainedModel. This property remains
empty until you pass data to the component during the learn phase.
To train the SVM model using the radial bias kernel, set the
KernelFunction property of the component to
"RBF".
component.KernelFunction = "RBF";Load the ionosphere data set and save the data in two tables.
load ionosphere
X = array2table(X);
Y = array2table(Y);Use the learn object function to train the
classificationSVMComponent using the entire data set.
component = learn(component,X,Y)
component =
classificationSVMComponent with properties:
Name: "ClassificationSVM"
Inputs: ["Predictors" "Response"]
InputTags: [1 2]
Outputs: ["Predictions" "Scores" "Loss"]
OutputTags: [1 0 0]
Learnables (HasLearned = true)
TrainedModel: [1×1 classreg.learning.classif.CompactClassificationSVM]
Structural Parameters (locked)
UseWeights: 0
Learn Parameters (locked)
KernelFunction: 'gaussian'
Show all parameters
Note that the HasLearned property is set to
true, which indicates that the software trained the classification
SVM model TrainedModel. You can use component to
classify new data using the run object function.
References
[1] Fan, R.-E., P.-H. Chen, and C.-J. Lin. “Working set selection using second order information for training support vector machines.” Journal of Machine Learning Research, Vol. 6, 2005, pp. 1889–1918.
[2] Kecman V., T. -M. Huang, and M. Vogt. “Iterative Single Data Algorithm for Training Kernel Machines from Huge Data Sets: Theory and Performance.” Support Vector Machines: Theory and Applications. Edited by Lipo Wang, 255–274. Berlin: Springer-Verlag, 2005.
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)