How can I test a trained Neural Network Model on new test data?

2 views (last 30 days)
Hi,
I am trying to test a trined NN model in MATLAB but it's giving the wrong output. I have trained the model on input of order 223x448 with labels as 223x1. And tested on the another set of order 114x448. where 114 comprises of two classes,each of the 57 labels for class 1 and clas 2. When i test the model it classify each class as one class; class 1 or class 2; and gives the confusion matrix of [57 57 ; 0 0]. Can anyone please help where i am doing this wrong.
The code to train the model:
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
hiddenLayerSize = [10 10 10];
net = patternnet(hiddenLayerSize, trainFcn);
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.performFcn = 'crossentropy'; % Cross-Entropy
net.plotFcns = {'plotconfusion'};
[net,tr] = train(net,train_f,train_L);
ANd this is how i test:
y = net(test_f);
e = gsubtract(test_L,y);
performance = perform(net,test_L,y);
tind = vec2ind(test_L);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
% Testing accuracy
[values,pred_ind]=max(y,[],1);
[~,actual_ind]=max(test_L,[],1);
accuracy=sum(pred_ind==actual_ind)/size(test_f,2)*100
fprintf('\n Classification Accuracy (NN): %g %%',accuracy);
[~,con]=confusion((test_L),y);
figure, plotconfusion(test_L,y)
Any help will be highly appreciated.
  1 Comment
Srivardhan Gadila
Srivardhan Gadila on 11 Mar 2020
In 223 training samples what is the count w.r.t class 1 and class 2?
Also can you check the confusion matrix on the training set after training the network?

Sign in to comment.

Answers (0)

Categories

Find more on Deep Learning Toolbox 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!