Main Content

regressionLayer

(Not recommended) 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.

layer = regressionLayer returns a regression output layer for a neural network as a RegressionOutputLayer object.

layer = regressionLayer(Name,Value) sets the optional Name and ResponseNames properties using name-value pairs. For example, regressionLayer('Name','output') creates a regression layer with the name 'output'. Enclose each property name in single quotes.

example

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

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: regressionLayer('Name','output') creates a regression layer with the name 'output'

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

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

Output Arguments

collapse all

Regression output layer, returned as a RegressionOutputLayer object.

More About

collapse all

Extended Capabilities

expand all

Version History

Introduced in R2017a

collapse all