My dataset consists of 322 samples in four categories, with the last column being labeled,Please help me take a look at my code and why the accuracy is very low?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
wentong
am 15 Jun. 2023
Kommentiert: Ranjeet
am 30 Jun. 2023
%% 读取数据
dataset=readmatrix('borsmote_data.xlsx');
sz = size(dataset);
dataset = dataset(randperm(sz(1)),:);
traindata=dataset(:,1:7);
trainlabel=categorical(dataset(:,8));
classes = unique(trainlabel)
numClasses = numel(unique(trainlabel))
%% 划分训练集和数据集
PD = 0.8 ;
Ptrain = []; Ttrain = [];
Ptest = []; Ttest = [];
for i = 1 : length(classes)
indi = find(trainlabel==classes(i));
indi = indi(randperm(length(indi)));
indj = round(length(indi)*PD);
Ptrain = [Ptrain; traindata(indi(1:indj),:)]; Ttrain = [Ttrain; trainlabel(indi(1:indj),:)];
Ptest = [Ptest; traindata(indi(1+indj:end),:)]; Ttest = [Ttest; trainlabel(indi(1+indj:end),:)];
end
Ptrain=(reshape(Ptrain', [7,1,1,size(Ptrain,1)]));
Ptest=(reshape(Ptest', [7,1,1,size(Ptest,1)]));
layers = [imageInputLayer([7 1 1])%输入层
convolution2dLayer([3 1],10,'Stride',1)
batchNormalizationLayer%批归一化
reluLayer%激活
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])%池化层
dropoutLayer
fullyConnectedLayer(numClasses)%全连接层输出大小
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',5000, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{Ptest,Ttest},...
'ExecutionEnvironment', 'cpu', ...
'ValidationPatience',Inf);
net = trainNetwork(Ptrain,Ttrain,layers,options);
Akzeptierte Antwort
Ranjeet
am 26 Jun. 2023
Hi Wentong,
As per the dataset/information provided, there are only 322 samples collectively for all the classes.
The dataset size seems to be quite small to get a good accuracy from a NN. I see that the number of epochs is set to 5000, but the primary reason for low accuracy seems the small dataset size.
It is suggested to get more data samples, there is no upper limit but training with 5000 data samples should show better accuracy.
Also, try maintaining a balanced dataset (equivalent size of data of each class).
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!