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 (최근 30일)
%% 读取数据
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.

채택된 답변

Ranjeet
Ranjeet 2023년 6월 26일
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
wentong
wentong 2023년 6월 30일
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 2023년 6월 30일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by