Contenuto principale

regressionNeuralNetworkComponent

Pipeline component for regression using neural network model

Since R2026a

    Description

    regressionNeuralNetworkComponent is a pipeline component that creates a feedforward, fully connected neural network for regression. The pipeline component uses the functionality of the fitrnet function during the learn phase to train a neural network model. The component uses the functionality of the predict and loss functions during the run phase to evaluate the model on new data.

    Creation

    Description

    component = regressionNeuralNetworkComponent creates a pipeline component for a neural network model for regression.

    example

    component = regressionNeuralNetworkComponent(Name=Value) sets writable Properties using one or more name-value arguments. For example, you can specify the activation functions, regularization term strength, and size of the fully connected layers.

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

    Activation functions for the fully connected layers of the neural network model, specified as one or more of the values in this table.

    ValueDescription
    "relu"

    Rectified linear unit (ReLU) function — Performs a threshold operation on each element of the input, where any value less than zero is set to zero, that is,

    f(x)={x,x00,x<0

    "tanh"

    Hyperbolic tangent (tanh) function — Applies the tanh function to each input element

    "sigmoid"

    Sigmoid function — Performs the following operation on each input element:

    f(x)=11+ex

    "none"

    Identity function — Returns each input element without performing any transformation, that is, f(x) = x

    If Activations is one of the table values, the component uses the specified activation function for each of the fully connected layers of the model, excluding the final fully connected layer. The activation function for the final fully connected layer is always softmax. For more information, see Neural Network Structure.

    If Activations is a string array or cell array of character vectors containing multiple table values, the component uses the ith element of Activations for the ith fully connected layer of the model.

    Example: c = regressionNeuralNetworkComponent(Activations="sigmoid")

    Example: c.Activations = ["relu","tanh"]

    Data Types: char | string | cell

    Relative gradient tolerance, specified as a nonnegative scalar.

    Let t be the loss function at training iteration t, t be the gradient of the loss function with respect to the weights and biases at iteration t, and 0 be the gradient of the loss function at an initial point. If max|t|aGradientTolerance, where a=max(1,min|t|,max|0|), the training process terminates.

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

    Example: c.GradientTolerance = 1e-7

    Data Types: single | double

    Initial step size, specified as a positive scalar or "auto". By default, the component does not use the initial step size to determine the initial Hessian approximation used to train the model. However, if you specify an initial step size s0, then the initial inverse-Hessian approximation is s00I. 0 is the initial gradient vector, and I is the identity matrix.

    If you specify "auto", the component determines an initial step size by using s0=0.5η0+0.1. s0 is the initial step vector, and η0 is the vector of unconstrained initial weights and biases.

    Example: c = regressionNeuralNetworkComponent(InitialStepSize="auto")

    Example: c.InitialStepSize = 0.2

    Data Types: single | double | char | string

    Maximum number of training iterations, specified as a positive integer scalar.

    When the component completes IterationLimit training iterations, it updates TrainedModel regardless of whether the training routine successfully converges.

    Example: c = regressionNeuralNetworkComponent(IterationLimit=1e8)

    Example: c.IterationLimit = 1e5

    Data Types: single | double

    Regularization term strength, specified as a nonnegative scalar. The component forms the objective function for minimization from the mean squared error (MSE) loss function and the ridge (L2) penalty term.

    Example: c = regressionNeuralNetworkComponent(Lambda=1e-4)

    Example: c.Lambda = 1e-2

    Data Types: single | double

    Type of initial fully connected layer biases, specified as "zeros" or "ones".

    If you specify "zeros", each fully connected layer has an initial bias value of 0. If you specify "ones", each fully connected layer has an initial bias value of 1.

    Example: c = regressionNeuralNetworkComponent(LayerBiasesInitializer="ones")

    Example: c.LayerBiasesInitializer = "zeros"

    Data Types: char | string

    Size of the fully connected layers in the neural network model, specified as a positive integer vector. The ith element of LayerSizes is the number of outputs in the ith fully connected layer of the neural network model.

    LayerSizes does not include the size of the final fully connected layer, which uses the softmax activation function. For more information, see Neural Network Structure.

    Example: c = regressionNeuralNetworkComponent(LayerSizes=[100 25 10])

    Example: c.LayerSizes = [50 20 10]

    Data Types: single | double

    Function used to initialize the fully connected layer weights, specified as "glorot" or "he".

    • If you specify "glorot", the component initializes the weights using the Glorot initializer [1] (also known as the Xavier initializer). For each layer, the Glorot initializer independently samples from a uniform distribution with zero mean and variance 2/(I+O), where I is the input size and O is the output size for the layer.

    • If you specify "he", the component initializes the weights using the He initializer [2]. For each layer, the He initializer samples from a normal distribution with zero mean and variance 2/I, where I is the input size for the layer.

    Example: c = regressionNeuralNetworkComponent(LayerWeightsInitializer="he")

    Example: c.LayerWeightsInitializer = "glorot"

    Data Types: char | string

    Loss tolerance, specified as a nonnegative scalar.

    If the function loss at an iteration is smaller than LossTolerance, the training process terminates.

    Example: c = regressionNeuralNetworkComponent(LossTolerance=1e-8)

    Example: c.LossTolerance = 1e-5

    Data Types: single | double

    Flag to standardize the predictor data, specified as a numeric or logical 0 (false) or 1 (true). If Standardize is true, the component centers and scales each numeric predictor variable by the corresponding column mean and standard deviation.

    Example: c = regressionNeuralNetworkComponent(Standardize=true)

    Example: c.Standardize = 0

    Data Types: single | double | logical

    Step size tolerance, specified as a nonnegative scalar.

    If the step size at an iteration is smaller than StepTolerance, the training process terminates.

    Example: c = regressionNeuralNetworkComponent(StepTolerance=1e-4)

    Example: c.StepTolerance = 1e-8

    Data Types: single | double

    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" (mean squared error) or a function handle.

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

    Example: c = regressionNeuralNetworkComponent(LossFun=@lossfun)

    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 = regressionNeuralNetworkComponent(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 = regressionNeuralNetworkComponent(Name="NeuralNetwork")

    Example: c.Name = "NeuralNetworkRegression"

    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 = regressionNeuralNetworkComponent(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 = regressionNeuralNetworkComponent(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 = regressionNeuralNetworkComponent(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 = regressionNeuralNetworkComponent(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 CompactRegressionNeuralNetwork 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 regressionNeuralNetworkComponent pipeline component.

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

    To standardize the predictor data, set the Standardize property to true.

    component.Standardize = true;

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

    load carsmall
    X = table(Cylinders,Displacement,Horsepower,Weight);
    Y = table(MPG);

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

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

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

    More About

    expand all

    References

    [1] Glorot, Xavier, and Yoshua Bengio. “Understanding the Difficulty of Training Deep Feedforward Neural Networks.” In Proceedings of the 13th International Conference on Artificial Intelligence and Statistics, 2010, pp. 249–256.

    [2] He, Kaiming, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. “Delving Deep into Rectifiers: Surpassing Human-Level Performance on Imagenet Classification.” In Proceedings of the IEEE International Conference on Computer Vision, 2015, pp. 1026–1034.

    Version History

    Introduced in R2026a

    See Also

    | |