getting error about wrong input argument

i have tried following code for upsampling of data with input values
smote('C:\Users\Haleema\Desktop\skin matlab\orignal', 8,{327,514,1099,115,1113,6705,142})
but got error
Error using bar (line 127)
Input arguments must be numeric, datetime, duration or categorical.
Error in barh (line 44)
h = bar(varargin{:});
Error in smote (line 22)
barh(sortedIDX);
function allData_smote = smote(allData, k,sortedIDX)
% mySMOTE Synthetic Minority Oversampling Technique. A technique to
% generate synthetic samples as given in: https://www.jair.org/media/953/live-953-2037-jair.pdf
% Usage:
% X_smote = mySMOTE(X, N, k)
%
% Inputs:
% allData: Original dataset
% k: number of nearest neighbors to consider while performing
% augmentation
% sortedIDX: sorted labels
%
% Outputs:
% X_smote: augmented dataset containing original data as well.
%
% See also datasample, randsample
%% plot the bar plot for number of classes
figure
barh(sortedIDX);
ylabel('number of classes-->')
xlabel('Sampels in each class-->')
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 class samples
[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('number of classes-->')
xlabel('Sampels in each class-->')
title('Balanced data distirbution')
%% randomize the data
shuffleindex=randperm(size(allData_smote,1));
allData_smote=allData_smote(shuffleindex,:);
end

5 Comments

'C:\Users\Haleema\Desktop\skin matlab\orignal' Is that a numeric value??
no its path of data
actually i don't understand what should be the arguments of function kindly suggest me something if you can
Haheema - how much of the above code have you modified from the original mySmote.m? If you are not the author of the above smote function, then you may want to contact whomever wrote it so that you can understand what the correct inputs should be.

Sign in to comment.

 Accepted Answer

smote('C:\Users\Haleema\Desktop\skin matlab\orignal', 8, [327,514,1099,115,1113,6705,142])
Not a cell array of numeric values, a numeric array of values.

6 Comments

i have tried this but same error
The first parameter to smote() must be a 2D numeric array. The last column must have class number information.
The second parameter must be a numeric scalar indicating the number of nearest neighbours to consider.
The third parameter must be a numeric column vector that lists all of the possible classes once.
This is not exactly what the original author had in mind, but it gives the least bad graph without interfering with the computation. The bar graph that is produced will not be useful. The third parameter can repeat entries without it interfering with the computation, but the graph would become more useless. (In order for the graph to be useful, the third parameter would have to be a 2D array, and each class label would have just happen to exactly match the number of rows that had that same label, and the number of columns would have to match the number of different classes.) To be honest, I think the processing of the third parameter is broken, and I cannot figure out what it was intended to be.
smote() does not usefully accept a character vector as the first parameter -- it would treat it as being a 1 x something numeric array.
thank you so much for your time and effort can you suggest me something for upsampling of imbalance data
You have to read your data that is stored in C:\Users\Haleema\Desktop\skin matlab\orignal first. smote() will not read it for you. smote() also will not process more than one array at a time.
It might make sense in some situations to read all of your files in at the same time and put them all together into one array, making sure to add a numeric class number as the last column of each row, and passing unique() of those entries as the third parameter.
I guess another way of putting things is that you can restrict which classes you want to work on by listing only those classes in the third parameter.

Sign in to comment.

More Answers (2)

Is it possible to apply mySMOTE on a cell array, say an array of 10 cells, each cell is 5000x12.
let me know.

1 Comment

No, it is not possible with the code linked to above.
You would have to cellfun() to apply the function to each element of the array.

Sign in to comment.

format long
v=[1,1/2,1/3,1/4,1/5,1/6,1/7];
t=2;
s=[];
w=linspace(-3.14/7,3.14/7,1000);
for k=w
z=t*exp(-i*k*7);
y=[v(1,1) t 0 0 0 0 z;t v(1,2) t 0 0 0 0;0 t v(1,3) t 0 0 0;0 0 t v(1,4) t 0 0;0 0 0 t v(1,5) t 0; 0 0 0 0 t v(1,6) t;z' 0 0 0 0 t v(1,7)];
u=eig(y);
s=[s,u];
end
%scatter(w,s(1,:))
%drawaxis(gca,'y',0)
%drawaxis(gca,'x',-4)
title('E_n_k(k) vs k')
xlabel('k')
ylabel('E_n_k(k)')
hold on
r=[1:7];
for n=r
plot(w,s(n,:),'LineWidth',2)
end
legend('n=1','n=2','n=3','n=4','n=5','n=6','n=7')

1 Comment

I am not clear how this is an answer to the question that was asked?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!