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.
returns a
regression output layer for a neural network as a layer
= regressionLayerRegressionOutputLayer
object.
sets the optional layer
= regressionLayer(Name,Value
)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.
Examples
Create Regression Output Layer
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
Input Arguments
Name-Value Arguments
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'
Name
— Layer name
""
(default) | character vector | string scalar
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
ResponseNames
— Names of responses
{}
(default) | cell array of character vectors | string array
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
layer
— Regression output layer
RegressionOutputLayer
object
Regression output layer, returned as a RegressionOutputLayer
object.
More About
Regression Output Layer
A regression layer computes the half-mean-squared-error loss for regression tasks. For typical regression problems, a regression layer must follow the final fully connected layer.
For a single observation, the mean-squared-error is given by:
where R is the number of responses, ti is the target output, and yi is the network’s prediction for response i.
For image and sequence-to-one regression networks, the loss function of the regression layer is the half-mean-squared-error of the predicted responses, not normalized by R:
For image-to-image regression networks, the loss function of the regression layer is the half-mean-squared-error of the predicted responses for each pixel, not normalized by R:
where H, W, and C denote the height, width, and number of channels of the output respectively, and p indexes into each element (pixel) of t and y linearly.
For sequence-to-sequence regression networks, the loss function of the regression layer is the half-mean-squared-error of the predicted responses for each time step, not normalized by R:
where S is the sequence length.
When training, the software calculates the mean loss over the observations in the mini-batch.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The code generator represents characters in an 8-bit ASCII codeset that the locale setting determines. Therefore, the use of non-ASCII characters in class names, layer names, layer description, or network names might result in errors. For more information, see Encoding of Characters in Code Generation (MATLAB Coder).
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
To generate CUDA® or C++ code by using GPU Coder™, you must first construct and train a deep neural network. Once the network is trained and evaluated, you can configure the code generator to generate code and deploy the convolutional neural network on platforms that use NVIDIA® or ARM® GPU processors. For more information, see Deep Learning with GPU Coder (GPU Coder).
For this layer, you can generate code that takes advantage of the NVIDIA CUDA deep neural network library (cuDNN), NVIDIA TensorRT™ high performance inference library, or the ARM
Compute Library
for Mali GPU.The code generator represents characters in an 8-bit ASCII codeset that the locale setting determines. Therefore, the use of non-ASCII characters in class names, layer names, layer description, or network names might result in errors. For more information, see Encoding of Characters in Code Generation (MATLAB Coder).
Version History
Introduced in R2017aR2024a: 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
supportsdlnetwork
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 adlnetwork
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 thantrainNetwork
.
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 Recommended | Recommended |
---|---|
net = trainNetwork(X,T,layers,options) ,
where layers contains a
RegressionOutputLayer object. | net = trainnet(X,T,layers,"mse",options); 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); layers specifies same
network without a RegressionOutputLayer
object. |
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)