plot confusion for backpropagation output

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)

Respuestas (1)

Srivardhan Gadila
Srivardhan Gadila el 28 de Mzo. de 2020

0 votos

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 comentarios

Tomasz Kaczmarski
Tomasz Kaczmarski el 28 de Mzo. de 2020
1)
2) please refer to orginal question
how to plot confusion chart across classes on test data against predicted from trainlm?as figure 3 from
, im happy to do it without classiffy - classify is causing error only
Srivardhan Gadila
Srivardhan Gadila el 28 de Mzo. de 2020
The network mentioned in https://uk.mathworks.com/matlabcentral/answers/367721-how-to-force-to-use-the-classify-from-the-neural-net-toolbox is a SeriesNetwork or a DAGNetwork object. You can get such a network by importing a pretrained network (for example, by using the googlenet function) or by training your own network using trainNetwork created using the layers mentioned in List of Deep Learning Layers documentation page.
Whereas the network that you have created using fitnet function is network object and is different from a SeriesNetwork or a DAGNetwork object and has the properties metioned in Neural Network Object Properties & Neural Network Subobject Properties.
Srivardhan Gadila
Srivardhan Gadila el 28 de Mzo. de 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 el 30 de Mzo. de 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 !!!

Iniciar sesión para comentar.

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 26 de Mzo. de 2020

Comentada:

el 30 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by