Main Content

RegressionOutputLayer

Regression output layer

regressionLayer is not recommended. Use the trainnet function and set the loss function to "mse" instead. For more information, see Version History.

Description

A regression layer computes the half-mean-squared-error loss for regression tasks.

Creation

Create a regression output layer using regressionLayer.

Properties

expand all

Regression Output

Names of the responses, specified a cell array of character vectors or a string array. At training time, the software automatically sets the response names according to the training data. The default is {}.

Data Types: cell

Loss function the software uses for training, specified as 'mean-squared-error'.

Layer

Layer name, specified as a character vector or a string scalar. For Layer array input, the trainNetwork function automatically assigns names to layers with the name "".

The RegressionOutputLayer object stores this property as a character vector.

Data Types: char | string

Number of inputs to the layer, returned as 1. This layer accepts a single input only.

Data Types: double

Input names, returned as {'in'}. This layer accepts a single input only.

Data Types: cell

Number of outputs of the layer, returned as 0. This layer has no outputs.

Data Types: double

Output names of the layer, returned as {}. This layer has no outputs.

Data Types: cell

Examples

collapse all

Create a regression output layer.

Create a regression output layer with the name 'routput'.

layer = regressionLayer('Name','routput')
layer = 
  RegressionOutputLayer with properties:

             Name: 'routput'
    ResponseNames: {}

   Hyperparameters
     LossFunction: 'mean-squared-error'

The default loss function for regression is mean-squared-error.

Include a regression output layer in a Layer array.

layers = [ ...
    imageInputLayer([28 28 1])
    convolution2dLayer(12,25)
    reluLayer
    fullyConnectedLayer(1)
    regressionLayer]
layers = 
  5x1 Layer array with layers:

     1   ''   Image Input         28x28x1 images with 'zerocenter' normalization
     2   ''   2-D Convolution     25 12x12 convolutions with stride [1  1] and padding [0  0  0  0]
     3   ''   ReLU                ReLU
     4   ''   Fully Connected     1 fully connected layer
     5   ''   Regression Output   mean-squared-error

More About

expand all

Version History

Introduced in R2017a

collapse all

R2024a: Not recommended

Starting in R2024a, RegressionOutputLayer objects are not recommended, use the trainnet and set the loss function to "mse" instead.

There are no plans to remove support for RegressionOutputLayer objects. However, the trainnet function has these advantages and is recommended instead:

  • trainnet supports dlnetwork objects, which support a wider range of network architectures that you can create or import from external platforms.

  • trainnet enables you to easily specify loss functions. You can select from built-in loss functions or specify a custom loss function.

  • trainnet outputs a dlnetwork object, which is a unified data type that supports network building, prediction, built-in training, visualization, compression, verification, and custom training loops.

  • trainnet is typically faster than trainNetwork.

This table shows some typical usages of the trainNetwork function with RegressionOutputLayer objects and how to update your code to use the trainnet function instead.

Not RecommendedRecommended
net = trainNetwork(X,T,layers,options), where layers contains a RegressionOutputLayer object.

net = trainnet(X,T,layers,"mse",options);
In this example, layers specifies same network without a RegressionOutputLayer object.

net = trainNetwork(data,layers,options), where layers contains a RegressionOutputLayer object.

net = trainnet(data,layers,"mse",options);
In this example, layers specifies same network without a RegressionOutputLayer object.