Main Content

CompactRegressionNeuralNetwork

Compact neural network model for regression

Since R2021a

    Description

    CompactRegressionNeuralNetwork is a compact version of a RegressionNeuralNetwork model object. The compact model does not include the data used for training the regression model. Therefore, you cannot perform some tasks, such as cross-validation, using the compact model. Use a compact model for tasks such as predicting the response values of new data.

    Creation

    Create a CompactRegressionNeuralNetwork object from a full RegressionNeuralNetwork model object by using compact.

    Properties

    expand all

    Neural Network Properties

    This property is read-only.

    Sizes of the fully connected layers in the neural network model.

    The property value depends on the method used to fit the model.

    • For models fit using a dlnetwork or layer array that specifies the neural network architecture, this property is empty. In this case, to examine the neural network architecture of the model, convert the model to a dlnetwork object using the dlnetwork (Deep Learning Toolbox) function.

    • Otherwise, the property is a positive integer vector, where the ith element of LayerSizes is the number of outputs in the ith fully connected layer of the neural network model. In this case, LayerSizes does not include the size of the final fully connected layer. This layer always has one output for each response variable.

    Data Types: single | double

    This property is read-only.

    Learned layer weights for the fully connected layers.

    The property value depends on the method used to fit the model.

    • For models fit using a dlnetwork or layer array that specifies the neural network architecture, this property is empty. In this case, to examine the learnable parameters of the model, convert the model to a dlnetwork object using the dlnetwork (Deep Learning Toolbox) function.

    • Otherwise, the property is a cell array, where entry i in the cell array corresponds to the layer weights for the fully connected layer i. For example, Mdl.LayerWeights{1} returns the weights for the first fully connected layer of the model Mdl. In this case, LayerWeights includes the weights for the final fully connected layer.

    Data Types: cell

    This property is read-only.

    Learned layer biases for the fully connected layers.

    The property value depends on the method used to fit the model.

    • For models fit using a dlnetwork or layer array that specifies the neural network architecture, this property is empty. In this case, to examine the learnable parameters of the model, convert the model to a dlnetwork object using the dlnetwork (Deep Learning Toolbox) function.

    • Otherwise, the property is a cell array, where entry i in the cell array corresponds to the layer biases for the fully connected layer i. For example, Mdl.LayerBiases{1} returns the biases for the first fully connected layer of the model Mdl. In this case, LayerBiases includes the biases for the final fully connected layer.

    Data Types: cell

    This property is read-only.

    Activation functions for the fully connected layers of the neural network model.

    The property value depends on the method used to fit the model.

    • For models fit using a dlnetwork or layer array that specifies the neural network architecture, this property is empty. In this case, to examine the neural network architecture of the model, convert the model to a dlnetwork object using the dlnetwork (Deep Learning Toolbox) function.

    • Otherwise, the property is a character vector or cell array of character vectors.

      If Activations contains only one activation function, then it is the activation function for every fully connected layer of the neural network model, excluding the final fully connected layer, which does not have an activation function (OutputLayerActivation).

      If Activations is an array of activation functions, then the ith element is the activation function for the ith layer of the neural network model.

    If Activations is a character vector or a cell array of character vectors, then the values are from 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

    Data Types: char | cell

    This property is read-only.

    Activation function for the final fully connected layer.

    The property value depends on the method used to fit the model.

    • For models fit using a dlnetwork or layer array that specifies the neural network architecture, this property is empty. In this case, to examine the neural network architecture of the model, convert the model to a dlnetwork object using the dlnetwork (Deep Learning Toolbox) function.

    • Otherwise, the property is 'none'.

    Data Properties

    This property is read-only.

    Predictor variable names, returned as a cell array of character vectors. The order of the elements of PredictorNames corresponds to the order in which the predictor names appear in the training data.

    Data Types: cell

    This property is read-only.

    Categorical predictor indices, returned as a vector of positive integers. Assuming that the predictor data contains observations in rows, CategoricalPredictors contains index values corresponding to the columns of the predictor data that contain categorical predictors. If none of the predictors are categorical, then this property is empty ([]).

    Data Types: double

    This property is read-only.

    Expanded predictor names, returned as a cell array of character vectors. If the model uses encoding for categorical variables, then ExpandedPredictorNames includes the names that describe the expanded variables. Otherwise, ExpandedPredictorNames is the same as PredictorNames.

    Data Types: cell

    Since R2023b

    This property is read-only.

    Predictor means, returned as a numeric vector. If you set Standardize to 1 or true when you train the neural network model, then the length of the Mu vector is equal to the number of expanded predictors (see ExpandedPredictorNames). The vector contains 0 values for dummy variables corresponding to expanded categorical predictors.

    If you set Standardize to 0 or false when you train the neural network model, then the Mu value is an empty vector ([]).

    Data Types: double

    This property is read-only.

    Names of the response variables, returned as a character vector or cell array of character vectors.

    Data Types: char | cell

    Response transformation function, specified as 'none' or a function handle. ResponseTransform describes how the software transforms raw response values.

    For a MATLAB® function or a function that you define, enter its function handle. For example, you can enter Mdl.ResponseTransform = @function, where function accepts the original response values and returns an output of the same size containing the transformed responses.

    Data Types: char | function_handle

    Since R2023b

    This property is read-only.

    Predictor standard deviations, returned as a numeric vector. If you set Standardize to 1 or true when you train the neural network model, then the length of the Sigma vector is equal to the number of expanded predictors (see ExpandedPredictorNames). The vector contains 1 values for dummy variables corresponding to expanded categorical predictors.

    If you set Standardize to 0 or false when you train the neural network model, then the Sigma value is an empty vector ([]).

    Data Types: double

    Object Functions

    expand all

    dlnetwork (Deep Learning Toolbox)Deep learning neural network
    limeLocal interpretable model-agnostic explanations (LIME)
    partialDependenceCompute partial dependence
    plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
    shapleyShapley values
    lossLoss for regression neural network
    predictPredict responses using regression neural network
    gatherGather properties of Statistics and Machine Learning Toolbox object from GPU

    Examples

    collapse all

    Reduce the size of a full regression neural network model by removing the training data from the model. You can use a compact model to improve memory efficiency.

    Load the patients data set. Create a table from the data set. Each row corresponds to one patient, and each column corresponds to a diagnostic variable. Use the Systolic variable as the response variable, and the rest of the variables as predictors.

    load patients
    tbl = table(Age,Diastolic,Gender,Height,Smoker,Weight,Systolic);

    Train a regression neural network model using the data. Specify the Systolic column of tblTrain as the response variable. Specify to standardize the numeric predictors.

    Mdl = fitrnet(tbl,"Systolic","Standardize",true)
    Mdl = 
      RegressionNeuralNetwork
               PredictorNames: {'Age'  'Diastolic'  'Gender'  'Height'  'Smoker'  'Weight'}
                 ResponseName: 'Systolic'
        CategoricalPredictors: [3 5]
            ResponseTransform: 'none'
              NumObservations: 100
                   LayerSizes: 10
                  Activations: 'relu'
        OutputLayerActivation: 'none'
                       Solver: 'LBFGS'
              ConvergenceInfo: [1×1 struct]
              TrainingHistory: [619×7 table]
    
    
      Properties, Methods
    
    

    Mdl is a full RegressionNeuralNetwork model object.

    Reduce the size of the model by using compact.

    compactMdl = compact(Mdl)
    compactMdl = 
      CompactRegressionNeuralNetwork
                   LayerSizes: 10
                  Activations: 'relu'
        OutputLayerActivation: 'none'
    
    
      Properties, Methods
    
    

    compactMdl is a CompactRegressionNeuralNetwork model object. compactMdl contains fewer properties than the full model Mdl.

    Display the amount of memory used by each neural network model.

    whos("Mdl","compactMdl")
      Name            Size            Bytes  Class                                                    Attributes
    
      Mdl             1x1             52240  RegressionNeuralNetwork                                            
      compactMdl      1x1              6769  classreg.learning.regr.CompactRegressionNeuralNetwork              
    

    The full model is larger than the compact model.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2021a

    expand all