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)
回答(1 个)
Srivardhan Gadila
2020-3-28
0 个投票
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:
- 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.
- 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 个评论
Tomasz Kaczmarski
2020-3-28
Srivardhan Gadila
2020-3-28
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
2020-3-28
The fitnet is used for regression. The confusion matrix is used for classification problems.
Tomasz Kaczmarski
2020-3-30
类别
在 帮助中心 和 File Exchange 中查找有关 Function Approximation and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!