主要内容

regressionKernelComponent

Pipeline component for regression using Gaussian kernel model

Since R2026a

    Description

    regressionKernelComponent is a pipeline component that creates a Gaussian kernel regression model with random feature expansion. The pipeline component uses the functionality of the fitrkernel function during the learn phase to train the kernel regression model. The component uses the functionality of the predict and loss functions during the run phase to perform regression.

    Creation

    Description

    component = regressionKernelComponent creates a pipeline component for a Gaussian kernel regression model.

    component = regressionKernelComponent(Name=Value) sets writable Properties using one or more name-value arguments. For example, you can specify the type of linear regression model, number of dimensions of the expanded space, and kernel scale parameter.

    example

    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 = regressionKernelComponent(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.

    Relative tolerance on the linear coefficients and the bias term (intercept), specified as a nonnegative scalar.

    Let Bt=[βtbt], that is, the vector of the coefficients and the bias term at optimization iteration t. If BtBt1Bt2<BetaTolerance, optimization terminates.

    If you also specify GradientTolerance, optimization terminates when the component satisfies either stopping criterion.

    Example: c = regressionKernelComponent(BetaTolerance=1e-6)

    Example: c.BetaTolerance = 1e-5

    Data Types: single | double

    Maximum amount of allocated memory (in megabytes), specified as a positive scalar.

    Example: c = regressionKernelComponent(BlockSize=1e4)

    Example: c.BlockSize = 1e3

    Data Types: single | double

    Box constraint, specified as a positive scalar.

    BoxConstraint is valid only when Learner is "svm" and Lambda is unset.

    Example: c = regressionKernelComponent(BoxConstraint=100)

    Example: c.BoxConstraint = 10

    Data Types: single | double

    Half width of the epsilon-insensitive band, specified as "auto" or a nonnegative scalar.

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

    Epsilon is valid only when Learner is "svm".

    Example: c = regressionKernelComponent(Epsilon=0.3)

    Example: c.Epsilon = "auto"

    Data Types: single | double | char | string

    Absolute gradient tolerance, specified as a nonnegative scalar.

    Let t be the gradient vector of the objective function with respect to the coefficients and bias term at optimization iteration t. If t=max|t|<GradientTolerance, optimization terminates.

    If you also specify BetaTolerance, optimization terminates when the component satisfies either stopping criterion.

    Example: c = regressionKernelComponent(GradientTolerance=1e-5)

    Example: c.GradientTolerance = 1e-4

    Data Types: single | double

    Size of the history buffer for the Hessian approximation, specified as a positive integer. At each iteration, the component composes the Hessian approximation using statistics from the latest HessianHistorySize iterations.

    Example: c = regressionKernelComponent(HessianHistorySize=10)

    Example: c.HessianHistorySize = 20

    Data Types: single | double

    Maximum number of optimization iterations, specified as a positive integer.

    The default value is 1000 if the transformed data fits in memory. Otherwise, the default value is 100.

    Example: c = regressionKernelComponent(IterationLimit=500)

    Example: c.IterationLimit = 700

    Data Types: single | double

    Kernel scale parameter, specified as "auto" or a positive scalar. The component obtains a random basis for random feature expansion by using the kernel scale parameter.

    If KernelScale is "auto", the component selects an appropriate kernel scale parameter using a heuristic procedure.

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

    Example: c.KernelScale = 0.1

    Data Types: single | double | char | string

    Regularization term strength, specified as "auto" or a nonnegative scalar. If Lambda is "auto", the value of Lambda is 1/n, where n is the number of observations in the first data argument of learn.

    When Learner is "svm", Lambda is valid only if BoxConstraint is unset.

    Example: c = regressionKernelComponent(Lambda=0.01)

    Example: c.Lambda = 0.1

    Data Types: single | double | char | string

    Linear regression model type, specified as "svm" or "leastsquares".

    If Learner is "svm", the component uses a support vector machine algorithm for linear regression. If Learner is "leastsquares", the component uses an ordinary least-squares algorithm for linear regression.

    Example: c = regressionKernelComponent(Learner="leastsquares")

    Example: c.Learner = "svm"

    Data Types: char | string

    Number of dimensions of expanded space, specified as "auto" or a positive integer.

    When NumExpansionDimensions is "auto", the component selects the number of dimensions using 2.^ceil(min(log2(p)+5,15)), where p is the number of predictors.

    Example: c = regressionKernelComponent(NumExpansionDimensions=2^15)

    Example: c.NumExpansionDimensions = "auto"

    Data Types: single | double | char | string

    Random number stream for reproducibility of the data transformation, specified as a random stream object.

    Use RandomStream to reproduce the random basis functions used by the component to transform the predictor data to a high-dimensional space. For details, see Managing the Global Stream Using RandStream and Creating and Controlling a Random Number Stream.

    Example: c = regressionKernelComponent(RandomStream=RandStream("mlfg6331_64"))

    Example: c.RandomStream = RandStream("mrg32k3a")

    Flag to standardize the predictors, specified as 0 (false) or 1 (true). If Standardize is true, the component centers and scales each column of the first data argument of learn by the column mean and standard deviation, respectively.

    The component does not standardize categorical predictors, and issues an error if all predictors are categorical.

    Example: c = regressionKernelComponent(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 "mse", "epsiloninsensitive", or a function handle.

    • If LossFun is "mse", the component uses the weighted mean squared error.

    • If LossFun is "epsiloninsensitive", the component uses the epsilon-insensitive loss.

    • If LossFun is a function handle, specify a custom loss function using function handle notation. For more information on custom loss functions, see LossFun.

    Example: c = regressionKernelComponent(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 = regressionKernelComponent(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 = regressionKernelComponent(Name="Kernel")

    Example: c.Name = "KernelRegression"

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

    Example: c = regressionKernelComponent(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 RegressionKernel 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 regressionKernelComponent pipeline component.

    component = regressionKernelComponent
    component = 
      regressionKernelComponent with properties:
    
                Name: "RegressionKernel"
              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 regressionKernelComponent object that contains one learnable, TrainedModel. This property remains empty until you pass data to the component during the learn phase.

    To use an ordinary least-squares regression algorithm for linear regression, set the Learner property of the component to "leastsquares".

    component.Learner = "leastsquares";

    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");

    Use the learn object function to train the regressionKernelComponent object using the entire data set.

    component = learn(component,X,Y)
    component = 
      regressionKernelComponent with properties:
    
                Name: "RegressionKernel"
              Inputs: ["Predictors"    "Response"]
           InputTags: [1 2]
             Outputs: ["Predictions"    "Loss"]
          OutputTags: [1 0]
    
       
    Learnables (HasLearned = true)
        TrainedModel: [1×1 RegressionKernel]
    
       
    Structural Parameters (locked)
          UseWeights: 0
    
       
    Learn Parameters (locked)
             Learner: 'leastsquares'
    
    
    Show all parameters
    

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

    Version History

    Introduced in R2026a

    See Also

    | |