how can i fix indexes for the train, val and test in train function? and how can i return the testing accuracy exactly like it appears in the plot confusion matrix?
5 views (last 30 days)
Show older comments
Dear Friends, i'm using the code below: to classify by berlin audio dataset, my dataset is not mixed, every group of audio files related are seperated from other groups,
please i have two questions: why isnt the fixed indexing working and how can i access the testing performance that appears in the confusion matrix of the the plotconfusion, please help me, a need it urgent in my work.
close all;
clear all;
clc;
%loading the berlin dataset
load berlin.mat;
%loading the target 0,1 matrix
load binary_matrix_berlin;
%rotating the both matrices
x = rot90(cell2mat(fin));
t = binary_matrix_berlin';
[ I N ] = size(x); % [ 2 1000]
[ O N ] = size(t); % [ 4 1000]
%there are seven groups in my dataset and i'm trying to classify them from each other, the set_1 is from file no. 1 to file number 69, the set_2 is from file no. 70 to file no. 115 an so on, so using the net.divideFcn = 'dividerand' doesnt work with me, i have to use the 'divideInd', but is not working, please help me in this issue.
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% Create a Pattern Recognition Network
hiddenLayerSize = [80 40];
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 = 'divideInd'; % Divide data by index
net.divideParam.trainnum = [1:42,70:97,116:158,187:235,268:315,347:384,409:485];
net.divideParam.valnum = [43:49,98:102,159:166,236:244,316:323,385:391,486:498];
net.divideParam.testnum = [50:69,103:115,167:186,245:267,324:346,392:408,499:535];
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
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,tr] = train(net,x,t);
%.........................................................
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
%a vector representing all the samples of the dataset predicted after
%training the NN.
yind = vec2ind(y);
%the percentage error of the all confusion matrix
percentErrors = sum(tind ~= yind)/numel(tind);
%...........................................................
% Recalculate Training, Validation and Test Performance
%in the list of functions listed below, non of them is giving me the testing performance, as it appears in the plotconfusion "test confusion matrix", please i need the function that can return the testing performance only, or its error percentage, "the testing results after applying the testing samples to the neural network only".
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)
3 Comments
Answers (0)
See Also
Categories
Find more on Define Shallow Neural Network Architectures 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!