Clear Filters
Clear Filters

plot confusion for backpropagation output

1 view (last 30 days)
Hello im trying to plot confusion matrix for all where i can see accuracy of each class
as shown in
unfortunellty im getting constant error
SWITCH expression must be a scalar or a character vector.
code is below
%PREPROCESSING
%load data
Tb = readtable('train1.csv','PreserveVariableNames',true);
Tbv = readtable('test1.csv','PreserveVariableNames',true);
%merge both datasets they can be splitted to train target later via dynamic
%parameter
Tbt = union(Tb, Tbv)
%split into train target
TrainSet = Tbt(:,(1:562))%data.simplefitInputs';
TargetSet = Tbt(:,(563:563));%data.simplefitTargets';
TargetSet= table2array(TargetSet)
%make some noise
TrainSetArray = table2array(TrainSet)
noiseSignal = cos(5 * pi * 100 * TrainSetArray)+sqrt(5) * randn(size(TrainSetArray));
%TRAINING
x = TrainSetArray';
%x = noiseSignal';
t = TargetSet';
%t = categorical(Tb(:,(563:563)));FAILING DURING TRAINING
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize,trainFcn);
% Create a Fitting Network
hiddenLayerSize = 1;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
%get output
y = net(x);
%get test set
testX = x(:,tr.testInd);
testT = t(:,tr.testInd);
testY = net(testX);
%PLOTTING CONFUSION MATRIXacorss classes as
% https://uk.mathworks.com/help/deeplearning/ref/plotconfusion.html
YPredicted = classify(net.myNet,testX)%Line Causing error SWITCH expression must be a scalar or a character vector.
plotconfusion(testy,YPredicted)

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 28 Mar 2020
The error is caused due to the input argument "net.myNet" in the classify function above.
The following are the errors in the above code:
  1. There is no object property named "myNet" for the above shallow neural network net. For information on properties of neural networks, refer to Neural Network Object Properties & Neural Network Subobject Properties.
  2. The function classify cannot be used on the above net object since it is a Shallow neural network and not a SeriesNetwork object or a DAGNetwork object. Refer to classify.
  4 Comments
Srivardhan Gadila
Srivardhan Gadila on 28 Mar 2020
The fitnet is used for regression. The confusion matrix is used for classification problems.
Refer to plotconfusion & confusionmat for more information
Tomasz Kaczmarski
Tomasz Kaczmarski on 30 Mar 2020
ok how to apply Levenberg-Marquardt backpropagation(trianlm) result to visualise problem as described above ?
you says its not possible ?
im not asking which alorithm to use but how to visualise output !!!

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!