Getting error In SMOTE
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!