主要内容

classificationKernelComponent

Pipeline component for classification using Gaussian kernel with random feature expansion

Since R2026a

    Description

    classificationKernelComponent is a pipeline component that creates a Gaussian kernel classifier using random feature expansion. The pipeline component uses the functionality of the fitckernel function during the learn phase to train the kernel classification model. The component uses the functionality of the predict and loss functions during the run phase to perform classification.

    Creation

    Description

    component = classificationKernelComponent creates a pipeline component for a Gaussian kernel classification model.

    example

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

    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 = classificationKernelComponent(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, then optimization terminates.

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

    Example: c = classificationKernelComponent(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 = classificationKernelComponent(BlockSize=1e4)

    Example: c.BlockSize = 1e3

    Data Types: single | double

    Box constraint, specified as a positive scalar.

    You can set this property only when Learner is "svm" and you do not specify a value for Lambda.

    Example: c = classificationKernelComponent(BoxConstraint=100)

    Example: c.BoxConstraint = 10

    Data Types: single | double

    Misclassification cost, specified as a square matrix or a structure.

    • If Cost is a square matrix, Cost(i,j) is the cost of classifying a point into class j if its true class is i.

    • If Cost is a structure S, it has two fields: S.ClassificationCosts, which contains the cost matrix; and S.ClassNames, which contains the group names and defines the class order of the rows and columns of the cost matrix.

    The default is Cost(i,j)=1 if i~=j, and Cost(i,j)=0 if i=j.

    Example: c = classificationKernelComponent(Cost=[0 1; 2 0])

    Example: c.Cost = [0 2; 1 0]

    Data Types: single | double | struct

    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, then optimization terminates.

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

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

    Example: c.GradientTolerance = 1e-4

    Data Types: single | double

    Size of the history buffer for 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 = classificationKernelComponent(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 = classificationKernelComponent(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 you specify "auto", then the component selects an appropriate kernel scale parameter using a heuristic procedure.

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

    Example: c.KernelScale = 0.1

    Data Types: single | double | char | string

    Regularization term strength, specified as "auto" or a nonnegative scalar. If you specify "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", you can specify Lambda only if you do not specify BoxConstraint.

    Example: c = classificationKernelComponent(Lambda=0.01)

    Example: c.Lambda = 0.1

    Data Types: single | double | char | string

    Linear classification model type, specified as "svm" or "logistic".

    If you specify "svm", the component uses a support vector machine algorithm for linear classification. If you specify "logistic", the component uses a logistic regression algorithm for linear classification.

    Example: c = classificationKernelComponent(Learner="logistic")

    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 = classificationKernelComponent(NumExpansionDimensions=2^15)

    Example: c.NumExpansionDimensions = "auto"

    Data Types: single | double | char | string

    Prior probabilities for each class, specified as a value in this table.

    ValueDescription
    "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 vectorA 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 S with two fields:

    • S.ClassNames contains a list of the class names.

    • S.ClassProbs contains a vector of corresponding prior probabilities. The component normalizes the elements such that they sum to 1.

    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 = classificationKernelComponent(Prior="uniform")

    Example: c.Prior = "empirical"

    Data Types: single | double | char | string | struct

    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 = classificationKernelComponent(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, then the component centers and scales each column of the first data input 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 = classificationKernelComponent(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.

    ValueDescription
    "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 = classificationKernelComponent(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.

    ValueDescription
    "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 + ex)
    "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 + ex) – 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 = classificationKernelComponent(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 = classificationKernelComponent(Name="Kernel")

    Example: c.Name = "KernelClassifier"

    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 = classificationKernelComponent(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 = classificationKernelComponent(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 = classificationKernelComponent(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 = classificationKernelComponent(OutputTags=[1 0 4])

    Example: c.OutputTags = [1 2 0]

    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 ClassificationKernel 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 classificationKernelComponent component.

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

    To use a logistic regression algorithm for linear classification, set the Learner property of the component to "logistic".

    component.Learner = "logistic";

    Load the ionosphere data set and save the data in two tables.

    load ionosphere
    X = array2table(X);
    Y = array2table(Y);

    Train the classificationKernelComponent object.

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

    Note that the HasLearned property is set to true, which indicates that the software trained the kernel model TrainedModel. You can use component to classify new data using the run function.

    Version History

    Introduced in R2026a

    See Also

    | |