Binary Classification _ problem with data structure

2 ビュー (過去 30 日間)
afef
afef 2017 年 6 月 27 日
コメント済み: afef 2017 年 6 月 28 日
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?

採用された回答

Greg Heath
Greg Heath 2017 年 6 月 28 日
There might be a caveat in the confusion matrix code that only accepts {0,1} 1-d outputs.
check it out.
Greg
  2 件のコメント
afef
afef 2017 年 6 月 28 日
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 2017 年 6 月 28 日
And i want to know when you said 1-d outputs. 'd' referes to what ??

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by