Contenuto principale

regressionSVMComponent

Pipeline component for regression using a support vector machine (SVM) model

Since R2026a

    Description

    regressionSVMComponent is a pipeline component that creates a support vector machine (SVM) model for regression. The pipeline component uses the functionality of the fitrsvm function during the learn phase to train the SVM regression model. The component uses the functionality of the predict and loss functions during the run phase to perform regression.

    Creation

    Description

    component = regressionSVMComponent creates a pipeline component for an SVM regression model.

    example

    component = regressionSVMComponent(Name=Value) sets writable Properties using one or more name-value arguments. For example, you can specify the kernel function, box constraint, and expected proportion of outliers.

    Properties

    expand all

    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 = regressionSVMComponent(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, and Alpha cannot contain any NaN values.

    By default, the component uses the value zeros(size(Y,1)), where Y is the second data argument of learn.

    Example: c = regressionSVMComponent(Alpha=0.1*ones(size(X,1),1))

    Example: c.Alpha = 0.5*ones(size(X,1),1)

    Data Types: single | double

    Box constraint for alpha coefficients, specified as a positive scalar value. The absolute value of the alpha coefficients cannot exceed the value of BoxConstraint.

    When KernelFunction is "gaussian" or "rbf", the default value of BoxConstraint is iqr(Y)/1.349, where Y is the second data argument of learn. Otherwise, the default value is 1.

    Example: c = regressionSVMComponent(BoxConstraint=10)

    Example: c.BoxConstraint = 100

    Data Types: single | double

    Cache size, specified as "maximal" or a positive scalar.

    • If CacheSize is "maximal", then the component reserves enough memory to hold the entire n-by-n Gram matrix.

    • If CacheSize is a positive scalar, then the component reserves CacheSize megabytes of memory for training the model.

    Example: c = regressionSVMComponent(CacheSize="maximal")

    Example: c.CacheSize = 2000

    Data Types: single | double | char | string

    Flag to clip alpha coefficients, specified as 1 (true) or 0 (false).

    • If ClipAlphas is true, then at each optimization iteration the component evaluates the alpha coefficients of the observations in the first data argument of learn. If the alpha coefficient of any observation is near 0 or near the box constraint of that observation, then the component sets the alpha coefficient of that observation to 0 or the box constraint value, respectively.

    • If ClipAlphas is false, then the component dose not change the alpha coefficients during optimization.

    The component stores the final alpha coefficient values in the Alpha property of TrainedModel.

    Example: c = regressionSVMComponent(ClipAlphas=false)

    Example: c.ClipAlphas = true

    Data Types: logical

    Tolerance for gradient difference between upper and lower violators obtained by SMO or ISDA, specified as a nonnegative scalar.

    This property is only valid when Solver is "SMO" or "ISDA".

    Example: c = regressionSVMComponent(DeltaGradientTolerance=1e-2)

    Example: c.DeltaGradientTolerance = 1e-4

    Data Types: single | double

    Half width of epsilon-insensitive band, specified as a nonnegative scalar value.

    The default value is iqr(Y)/13.49, which is an estimate of a tenth of the standard deviation using the interquartile range of the second data input of learn, or Y. If iqr(Y) is equal to zero, then the component uses the value 0.1.

    Example: c = regressionSVMComponent(Epsilon=0.3)

    Example: c.Epsilon = 0.1

    Data Types: single | double

    Feasibility gap tolerance obtained by SMO or ISDA, specified as a nonnegative scalar. If GapTolerance is 0, then the component does not use this parameter to check for convergence.

    This property is only valid when Solver is "SMO" or "ISDA".

    Example: c = regressionSVMComponent(GapTolerance=1e-2)

    Example: c.GapTolerance = 0.1

    Data Types: single | double

    Maximal number of numerical optimization iterations, specified as a positive integer.

    Once the component has executed IterationLimit iterations, it updates TrainedModel with a trained SVM model regardless of whether the optimization routine successfully converges.

    Example: c = regressionSVMComponent(IterationLimit=1e8)

    Example: c.IterationLimit = 1e7

    Data Types: single | double

    Kernel function used to compute the Gram matrix, specified as a function handle or a value in this table.

    Kernel Function NameDescriptionFormula
    "gaussian" or "rbf"Gaussian or Radial Basis Function (RBF) kernel, default for one-class learning

    G(xj,xk)=exp(xjxk2)

    "linear"Linear kernel, default for two-class learning

    G(xj,xk)=xjxk

    "polynomial"Polynomial kernel. Use PolynomialOrder to specify the order of the polynomial kernel.

    G(xj,xk)=(1+xjxk)q

    To specify a custom kernel function, define a function that accepts two matrices, U and V, as inputs and returns a Gram matrix of the rows of U and V. The custom function must be on the MATLAB path.

    Example: c = regressionSVMComponent(KernelFunction="gaussian")

    Example: c.KernelFunction = "polynomial"

    Data Types: char | string

    Kernel offset parameter, specified as a nonnegative scalar. The component adds KernelOffset to each element in the Gram matrix.

    This property is only valid when Solver is "SMO" or "ISDA".

    The default value is 0 if Solver is "SMO" and 0.1 if Solver is "ISDA".

    Example: c = regressionSVMComponent(KernelOffset=0)

    Example: c.KernelOffset = 0.1

    Data Types: single | double

    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 you specify "auto", then the component selects an appropriate scale factor using a heuristic procedure. This procedure uses subsampling, so estimates can vary between calls.

    This argument is only valid when KernelFunction is a built-in function name. If you specify a custom kernel function, you must apply scaling within the function.

    Example: c = regressionSVMComponent(KernelScale="auto")

    Example: c.KernelScale = 0.1

    Data Types: single | double | char | string

    Tolerance for Karush-Kuhn-Tucker (KKT) violation, specified as a nonnegative scalar value. If KKTTolerance is 0, then the component does not use the KKT complimentary conditions violation tolerance to check for optimization convergence.

    This property is only valid when Solver is "SMO" or "ISDA".

    Example: c = regressioSVMComponent(KKTTolerance=1e-2)

    Example: c.KKTTolerance = 1e-3

    Data Types: single | double

    Expected proportion of outliers in training data, specified as a numeric scalar in the interval [0,1). The component removes observations with large gradients, ensuring that the component removes the fraction of observations specified by OutlierFraction by the time convergence is reached.

    This property is only valid when Solver is "ISDA".

    Example: c = regressionSVMComponent(OutlierFraction=0.01)

    Example: c.OutlierFraction = 0.1

    Data Types: single | double

    Polynomial kernel function order, specified as a positive integer.

    This argument is only valid when KernelFunction is "polynomial".

    Example: c = regressionSVMComponent(PolynomialOrder=2)

    Example: c.PolynomialOrder = 3

    Data Types: single | double

    Flag to replace duplicate observations with single observations in the training data, specified as 0 (false) or 1 (true).

    If RemoveDuplicates is true, then the component replaces duplicate observations with a single observation of the same value. If you enable UseWeights, then the weight of the single observation is equal to the sum of the weights of the corresponding removed duplicates.

    Example: c = regressionSVMComponent(RemoveDuplicates=true)

    Example: c.RemoveDuplicates = false

    Data Types: logical

    Number of iterations between reductions of the active set, specified as a nonnegative integer.

    If ShrinkagePeriod is 0, then the component does not shrink the active set.

    Example: c = regressionSVMComponent(ShrinkagePeriod=1000)

    Example: c.ShrinkagePeriod = 5000

    Data Types: single | double

    Optimization routine, specified as a value in this table.

    ValueDescription
    "ISDA"Iterative Single Data Algorithm
    "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

    The default value is "ISDA" if you set OutlierFraction to a positive value and "SMO" otherwise.

    Example: c = regressionSVMComponent(Solver="ISDA")

    Example: c.Solver = "SMO"

    Flag to standardize the predictor data, specified as 0 (false) or 1 (true).

    If you set Standardize to true, then the component centers and scales each predictor variable by its weighted mean and standard deviation. The component does not standardize the data contained in the dummy variable columns generated for categorical predictors.

    Example: c = regressionSVMComponent(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.

    • "mse" — Weighted mean squared error.

    • "epsiloninsensitive" — Epsilon-insensitive loss.

    • Function handle — To specify a custom loss function, use function handle notation. For more information on custom loss functions, see LossFun.

    Example: c = regressionSVMComponent(LossFun="epsiloninsensitive")

    Example: c.LossFun = "mse"

    Data Types: char | string | function_handle

    Function for transforming raw response values, specified as a function handle or function name. The default is "none", which means @(y)y, or no transformation. The function must accept a vector (the original response values) and return a vector of the same size (the transformed response values).

    Example: c = regressionSVMComponent(ResponseTransform=@(y)exp(y))

    Example: c.ResponseTransform = "exp"

    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 = regressionSVMComponent(Name="SVM")

    Example: c.Name = "SVMRegression"

    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 software adds the input port "Weights" to Inputs.

    Example: c = regressionSVMComponent(Inputs=["X","Y"])

    Example: c.Inputs = ["X1","Y1"]

    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 = regressionSVMComponent(Outputs=["Responses","LossVal"])

    Example: c.Outputs = ["X","Y"]

    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, then the number of tags must match the number of inputs in Inputs. If UseWeights is true, the software adds a third input tag to InputTags.

    Example: c = regressionSVMComponent(InputTags=[0 1])

    Example: c.InputTags = [1 0]

    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, then the number of tags must match the number of outputs in Outputs.

    Example: c = regressionSVMComponent(OutputTags=[0 1])

    Example: c.OutputTags=[1 2]

    Data Types: single | double

    This property is read-only.

    Indicator for the 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 CompactRegressionSVM model object.

    Object Functions

    learnInitialize and evaluate pipeline or component
    runExecute pipeline or component for inference after learning
    resetReset pipeline or component
    seriesConnect components in series to create pipeline
    parallelConnect components or pipelines in parallel to create pipeline
    viewView diagram of pipeline inputs, outputs, components, and connections

    Examples

    collapse all

    Create a regressionSVMComponent component.

    component = regressionSVMComponent
    component = 
    
      regressionSVMComponent with properties:
    
                Name: "RegressionSVM"
              Inputs: ["Predictors"    "Response"]
           InputTags: [1 2]
             Outputs: ["Predictions"    "Loss"]
          OutputTags: [1 0]
    
       
    Learnables (HasLearned = false)
        TrainedModel: []
    
       
    Structural Parameters (locked)
          UseWeights: 0
    
    
    Show all parameters

    component is a regressionSVMComponent object that contains one learnable, TrainedModel. This property remains empty until you pass data to the component during the learn phase.

    To optimize using the iterative single data algorithm, set the Solver property of the component to "ISDA".

    component.Solver = "ISDA";

    Load the carsmall data set and remove missing entries from the data. Separate the predictor and response variables into two tables.

    load carsmall
    carData = table(Cylinders,Displacement,Horsepower,Weight,MPG);
    R = rmmissing(carData);
    X = R(:,["Cylinders","Displacement","Horsepower","Weight"]);
    Y = R(:,"MPG");

    Train the regressionSVMComponent.

    component = learn(component,X,Y)
    component = 
      regressionSVMComponent with properties:
    
                Name: "RegressionSVM"
              Inputs: ["Predictors"    "Response"]
           InputTags: [1 2]
             Outputs: ["Predictions"    "Loss"]
          OutputTags: [1 0]
    
       
    Learnables (HasLearned = true)
        TrainedModel: [1×1 classreg.learning.regr.CompactRegressionSVM]
    
       
    Structural Parameters (locked)
          UseWeights: 0
    
       
    Learn Parameters (locked)
              Solver: 'ISDA'
    
    
    Show all parameters
    

    Note that the HasLearned property is set to true, which indicates that the software trained the SVM model TrainedModel. You can use component to predict response values for new data using the run function.

    Version History

    Introduced in R2026a

    See Also

    | |