How to test neural network trained model?
41 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
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
view(net)
0 comentarios
Respuestas (1)
Srivardhan Gadila
el 11 de Mzo. de 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.
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!