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?

2 views (last 30 days)
%% 读取数据
dataset=readmatrix('borsmote_data.xlsx');
sz = size(dataset);
dataset = dataset(randperm(sz(1)),:);
traindata=dataset(:,1:7);
trainlabel=categorical(dataset(:,8));
classes = unique(trainlabel)
classes = 4×1 categorical array
1 2 3 4
numClasses = numel(unique(trainlabel))
numClasses = 4
%% 划分训练集和数据集
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);
Error using trainNetwork
This functionality is not available on remote platforms.

Caused by:
Error using matlab.internal.lang.capability.Capability.require
This functionality is not available on remote platforms.

Accepted Answer

Ranjeet
Ranjeet on 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 Comments
wentong
wentong on 30 Jun 2023
It's a great pleasure to communicate with you
Is there no optimization algorithm that can improve accuracy?such as PSO,But I don't quite understand how to add the above code
Ranjeet
Ranjeet on 30 Jun 2023
As per the code and dataset provided, the suggested approach would be to add more samples to the dataset (as suggested in the answer) to improve accuracy. PSO algorithm would not be useful in this context to increase accuracy.

Sign in to comment.

More Answers (0)

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!