Can I use "softmaxLayer" for regression network?

H
heemasingh · Apr 11, 2022 · 2K views
Question
Can I use "softmaxLayer" for regression network?
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 25, 2026
A softmax layer normalizes the input to the layer such that its elements sum up to 1. Therefore, it is useful when you want the network to compute a probability of a classification problem, since it ensures that the sum of the scores over the classes is 1, as requested for a probability measure.
 
However, it can be used also in combination with other layers as long as it makes sense to normalize the inputs to sum up to 1.
 
 
Thus, you can use "softmaxLayer" in MATLAB for your regression problem (although assessing its effectiveness would depend on the problem you are trying to solve at hand).
 
For example, you can create the following deep learning network:
 
 
>> layers = [ ...
>>    imageInputLayer([28 28 1]), ...
>>    convolution2dLayer(12,25), ...
>>    softmaxLayer, ...
>>    fullyConnectedLayer(1), ...
>>    regressionLayer]
Currently, a"softmaxLayer" cannot directly precede a "regressionLayer", which is why a "fullyConnectedLayer" is between the two in the above example. However, another workaround would be to define a custom regression output layer and a custom softmax layer. If you use a custom layers instead of the layers provided in the Deep Learning Toolbox, you can have a softmax layer immediately before a regression layer.
 
Here is what the "layers" array in the above example would look like using custom layers called "mySoftmaxLayer" and "myRegressionLayer":
 
>> layers = [ ...
>>    imageInputLayer([28 28 1]), ...
>>    convolution2dLayer(12,25), ...
>>    mySoftmaxLayer, ...
>>    myRegressionLayer]

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!