Binary Classification _ problem with data structure
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
afef
el 27 de Jun. de 2017
Comentada: afef
el 28 de Jun. de 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?
0 comentarios
Respuesta aceptada
Greg Heath
el 28 de Jun. de 2017
There might be a caveat in the confusion matrix code that only accepts {0,1} 1-d outputs.
check it out.
Greg
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!