Getting error In SMOTE
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emma Skye
am 10 Mär. 2022
Kommentiert: Emma Skye
am 13 Mär. 2022
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
0 Kommentare
Akzeptierte Antwort
Voss
am 11 Mär. 2022
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 Kommentare
Voss
am 11 Mär. 2022
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Performance and Memory 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!