Getting error In SMOTE

조회 수: 10 (최근 30일)
Emma Skye
Emma Skye 2022년 3월 10일
댓글: Emma Skye 2022년 3월 13일
I have tried the following code for SMOTE with input values .
separate m.file (func_smot.m)
function allData_smote = func_smot(allData, k,sortedIDX)
%% plot the bar plot for number of classes
figure
% barh(sortedIDX)
ylabel('4')
xlabel('2552,227,621,2555')
title('Original imbalance data distirbution')
%% number of each classes
labels=allData(:,end);
class=unique(sortedIDX);
for ii=1:numel(class)
classNo(ii)=numel(find(labels==class(ii)));
end
%% required addon samples in each minority class
%add on samples will be calculated by taking the difference of each
%classSamples with highest number of cla ss samples
maximumSamples=2555;
sampleClass=5955;
[maximumSamples,sampleClass]=max(classNo); % number of maximum samples
for ii=1:numel(class)
samplediff(ii)=maximumSamples-classNo(ii);
N (ii) = ceil(samplediff(ii)/ 100);
end
%% oversample the minority classes
allData_smote=[];
for ii=1:numel(class)
X=allData(labels==class(ii),:);
T = size(X, 1);
X_smote = X;
for i = 1:T
y = X(i,:);
% find k-nearest samples
[idx, ~] = knnsearch(X,y,'k',k);
% retain only N out of k nearest samples
idx = datasample(idx, N(ii));
x_nearest = X(idx,:);
x_syn = bsxfun(@plus, bsxfun(@times, bsxfun(@minus,x_nearest,y), rand(N(ii),1)), y);
X_smote = cat(1, X_smote, x_syn);
end
allData_smote=cat(1,allData_smote,X_smote);
end
%%
balanced_sortedIDX=allData_smote(:,end);
figure
barh(balanced_sortedIDX)
ylabel('4')
xlabel('2552,227,621,2555')
title('Balanced data distirbution')
%% randomize the data
shuffleindex=randperm(size(allData_smote,1));
allData_smote=allData_smote(shuffleindex,:);
end
separate m-file(mySMOTE.m)
your_allData = [5955,4];
your_k = 5;
your_sortedIdx = {'2552','227','621','2555'};
your_result = mySMOTE(your_allData,your_k,your_sortedIdx);
It is giving me this error
>> func_smot
Not enough input arguments.
Error in func_smot (line 9)
labels=allData(:,end);
Could anyone please help me. It would be greatly appreciated!
I appreciate your help in advance

채택된 답변

Voss
Voss 2022년 3월 11일
It sounds like you are attempting to run func_smot.m by clicking the green arrow or hitting F5, but you mean to be running mySMOTE.m like that.
Also it seems like mySMOTE.m should call func_smot, rather than attempting to call itself. I've made that change to mySMOTE.m and attached it. (Attached func_smot.m is unchanged.)
Take that change to mySMOTE.m, and try running it using the green arrow or F5 or entering mySMOTE on the command line.
  댓글 수: 3
Voss
Voss 2022년 3월 11일
I believe you should not be running func_smot by clicking the green arrow or hitting F5.
Instead you should be running mySMOTE.
mySMOTE will call func_smot with the input arguments specified in mySMOTE
% set up inputs for func_smot:
your_allData = [5955,4];
your_k = 5;
your_sortedIdx = {'2552','227','621','2555'};
% call func_smot with those inputs:
your_result = func_smot(your_allData,your_k,your_sortedIdx);
Emma Skye
Emma Skye 2022년 3월 13일
Thanks a bunch !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by