Effacer les filtres
Effacer les filtres

How to test neural network trained model?

67 vues (au cours des 30 derniers jours)
Joana le 7 Mar 2020
Commenté : Joana le 13 Mar 2020
I am using NN for classification purpose, i know how to do this for one subject, by didviding the data in training:testing:validation sets. But i want to train my network on one subject's entire data and test it on the other subject's data.
I am confused how to do this.? How to pass on the labels and test input to the model.?
I have searched and i learned to save the network, then load it and run with the new test set as an input. I get that but what about the labels, how should i pass on the new labels for the test set.?
Please help.!
Following is the code:
clear all
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
hiddenLayerSize = [10 10 10];
net = patternnet(hiddenLayerSize, trainFcn);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
%% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 10/100;
net.divideParam.testRatio = 20/100;
%% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'crossentropy'; % Cross-Entropy
net.trainParam.max_fail = 300;
net.trainParam.min_grad = 0.00000001;
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotconfusion', 'plotroc'};
%% Train the Network
[net,tr] = train(net,Input_Signals,Labels);
%% Test the Network
y = net(Input_Signals);
e = gsubtract(Labels,y);
performance = perform(net,Labels,y)
tind = vec2ind(Labels);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
%% Recalculate Training, Validation and Test Performance
trainTargets = Labels .* tr.trainMask{1};
valTargets = Labels .* tr.valMask{1};
testTargets = Labels .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
%% View the Network

Réponses (1)

Srivardhan Gadila
Srivardhan Gadila le 11 Mar 2020
In "Test the Network section" from the above code of yours, replace Input_Signals with new test set and Labels with the labels of new test set.
  1 commentaire
Joana le 13 Mar 2020
I did that, but it classifies everything as one class, resulting the 50% accuracy. Although i am training and testing the model with equal number of samples for each class.
Any idea what could be the problem.?
I implemented LDA as well, with training on one set and testing on other, but results are same as 50-53%. i don't know why.?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by