Filter löschen
Filter löschen

getting error about wrong input argument

16 Ansichten (letzte 30 Tage)
Haleema Ahsan
Haleema Ahsan am 2 Jul. 2020
Kommentiert: Walter Roberson am 21 Okt. 2021
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 Kommentare
Geoff Hayes
Geoff Hayes am 3 Jul. 2020
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.
Haleema Ahsan
Haleema Ahsan am 3 Jul. 2020
ok thanks

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Jul. 2020
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 Kommentare
Haleema Ahsan
Haleema Ahsan am 4 Jul. 2020
OK thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Mohanad Alkhodari
Mohanad Alkhodari am 11 Aug. 2020
Is it possible to apply mySMOTE on a cell array, say an array of 10 cells, each cell is 5000x12.
let me know.
  1 Kommentar
Walter Roberson
Walter Roberson am 11 Aug. 2020
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.

Melden Sie sich an, um zu kommentieren.


Ajay Atwal
Ajay Atwal am 21 Okt. 2021
Bearbeitet: Walter Roberson am 21 Okt. 2021
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 Kommentar
Walter Roberson
Walter Roberson am 21 Okt. 2021
I am not clear how this is an answer to the question that was asked?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images 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!

Translated by