How to test neural network trained model?

조회 수: 52 (최근 30일)
Joana . 2020년 3월 7일
댓글: Joana . 2020년 3월 13일
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

답변 (1개)

Srivardhan Gadila
Srivardhan Gadila 2020년 3월 11일
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
Joana 2020년 3월 13일
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.?

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Pattern Recognition and Classification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by