Filter löschen
Filter löschen

trainlm predict value & switch

3 Ansichten (letzte 30 Tage)
Tomasz Kaczmarski
Tomasz Kaczmarski am 15 Mär. 2020
Kommentiert: Tomasz Kaczmarski am 23 Mär. 2020
output of trained network is y from
load data
Tb = readtable('train1.csv','PreserveVariableNames',true)
x = Tb(:,(1:562))%data.simplefitInputs';
t = Tb(:,(563:563));%data.simplefitTargets';
[net,tr] = train(net,x,t);
y = net(x);
as target were classes 1,2,3,4,5,6
why output is 1.123 , 4.454, 5.6575 etc not same classes as input?
and how to convert output y to predicted value ?
YPredicted = classify(net.myNet,y)
returns error:
SWITCH expression must be a scalar or a character vector.
Error in network/subsref (line 173)
switch (subs)
my final output would be confusionmatrix
plotconfusion(YTest,YPredicted)

Antworten (1)

Mahesh Taparia
Mahesh Taparia am 18 Mär. 2020
Bearbeitet: Mahesh Taparia am 18 Mär. 2020
Hi
In my understanding, you want classification output and you are getting regression output. Convert the variable 't' into a categorical array before training the model and check if it is working or not, i.e
t = categorical(Tb(:,(563:563)));
  3 Kommentare
Mahesh Taparia
Mahesh Taparia am 19 Mär. 2020
Hi
The below is the working code for classification of your application. Hope it will helps.
Train= load('TrainSetArray.mat')
Target = load('TargetSetArray.mat')
% avaliable under
%https://drive.google.com/open?id=1CzfnIY5DZqcu8Vt-zxM3I6sVLnzLhwK5
x = Train.TrainSetArray;
t = Target.TargetSet;
t1=ind2vec(t');
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 1;
net = patternnet(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',t1);
y = net(x');%%%%% include the test vectors here
perf = perform(net,t,y);
classes = vec2ind(y);
Tomasz Kaczmarski
Tomasz Kaczmarski am 23 Mär. 2020
Hi
apologise but its not working im getting
In test (line 14)
Error using bsxfun
Non-singleton dimensions of the two input arrays must match each other.
Error in gsubtract>calc_general (line 40)
c = bsxfun(@minus,a,b);
additionally im trying to achive is confusion matrix across classes mine 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)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by