Binary Classification _ problem with data structure

1 Ansicht (letzte 30 Tage)
afef
afef am 27 Jun. 2017
Kommentiert: afef am 28 Jun. 2017
Hi, i want to create neural network for binary classification so when i read in matlab doc for patternet that Classification problems involving only two classes can be represented using either format. The targets can consist of either scalar 1/0 elements or two-element vectors, with one element being 1 and the other element being 0.(link= https://www.mathworks.com/help/nnet/gs/classify-patterns-with-a-neural-network.html) so i tried to set each scalar target value to either 0 or 1 but in the confusion matrix i got NAN values for the second class
[ I N ] = [ 9 981 ]
[ O N ] = [ 1 981 ]
And this is the code
rng('default');
x = patientInputs;
t = patientTargets ;
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% Create a Pattern Recognition Network
hiddenLayerSize =10;
net = patternnet(hiddenLayerSize);
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.performFcn = 'mse'; % Cross-Entropy
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotconfusion', 'plotroc'};
% Train the Network
net= configure(net,x,t);
[net,tr] = train(net,x,t);
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
% Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
view(net)
i don't know why? can anyone tell me please?

Akzeptierte Antwort

Greg Heath
Greg Heath am 28 Jun. 2017
There might be a caveat in the confusion matrix code that only accepts {0,1} 1-d outputs.
check it out.
Greg
  2 Kommentare
afef
afef am 28 Jun. 2017
I thought that the problem is wwith this part in the code
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
Because when i removed
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
and i change it with this
inputs = patientInputs;
targets = patientTargets;
x = mapminmax(inputs);
t=targets;
it works .So i want to know am i doing right ?
afef
afef am 28 Jun. 2017
And i want to know when you said 1-d outputs. 'd' referes to what ??

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by