Wrong output from network function, exported from nprtool
显示 更早的评论
Trained a neural pattern recognition network (nprtool) using 4x23458 Matrix as the predictors. The target is boolean. I was happy with the results and exported the function into workspace:
function [y1] = myNeuralNetworkFunction(x1)
Now its returning double instead of boolean if i feed it with a sample of the training data. Im quite sure there is an easy fix to this. Really a novice in using neural network functions in matlab.
Thank you.
采纳的回答
更多回答(2 个)
Aneela
2024-10-10
Hi Thomas,
When you train a neural network for binary classification using MATLAB's Neural Pattern Recognition Tool (nprtool), the network outputs a continuous value. This value typically ranges between 0 and 1, representing the probability that the input belongs to the positive class.
To convert the continuous output to a Boolean value, you can apply a threshold.
output = myNeuralNetworkFunction(x1);
booleanOutput = output >= 0.5;
This operation will return 1 for values(probabilities) greater than or equal to 0.5 and 0 otherwise.
You can refer to the documentation below for more information on “nprtool”: https://www.mathworks.com/help/deeplearning/gs/pattern-recognition-with-a-shallow-neural-network.html
praguna manvi
2024-10-10
As I understand it, you are trying to predict the class using the trained “patternnet” loaded from workspace. To convert the double values from the network to class labels, you can use the “vec2ind” function and “ind2vec” to obtain a sparse vector output. Here is an example from the documentation of “patternnet”:
y = net(x);
tind = vec2ind(t); % test outputs
yind = vec2ind(y);
percentErrors = sum(tind ~= yind) / numel(tind);`
For more information on how to use “patternnet” from the command line, please refer to this link:
Hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Pattern Recognition 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!