Data normalization for training ANN model and getting negative output values
7 views (last 30 days)
Show older comments
I am using ANN for training a model, do I need to normalize my output "target data" also, or just normalizing the input variables are sufficient? also, all my target values are positive but after training the network I get some negative values which it does not make any sence in my case, be noted I have used logsigmoid function as my activation function.
Regards
0 Comments
Answers (1)
Rushil
on 28 Apr 2025
Hi
When working with ANNs in MATLAB, especially using the “logsig” (log-sigmoid) activation function in the output layer, it is important to normalize both input and output (target) data. The “logsig” function outputs values strictly in the range (0, 1), so the target data should be scaled to this interval before training to ensure the network can learn the correct mapping.
Below is an example workflow illustrating this process:
% assuming you have inputData and targetData
[inputNorm, inputSettings] = mapminmax(inputData, 0, 1);
[targetNorm, targetSettings] = mapminmax(targetData, 0, 1);
net = feedforwardnet(hiddenLayerSize); % assuming a general hidden layer network
net.layers{end}.transferFcn = 'logsig';
[net, trainInfo] = train(net, inputNorm, targetNorm);
% save the network if needed
testInputNorm = mapminmax('apply', testInputData, inputSettings);
outputNorm = net(testInputNorm);
output = mapminmax('reverse', outputNorm, targetSettings); % reverse the normalization
In this workflow, both the inputs and targets are scaled to the [0, 1] range using “mapminmax” before training. After training, predictions are made using normalized test data, and the outputs are then transformed back to the original scale using the same normalization parameters. This approach ensures the network's outputs are meaningful and within the expected range. To know more about “mapminmax”, refer to to the following MathWorks Documentation link below:
Hope it helps
0 Comments
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!