getting error about wrong input argument

7 ビュー (過去 30 日間)
Haleema Ahsan
Haleema Ahsan 2020 年 7 月 2 日
コメント済み: Walter Roberson 2021 年 10 月 21 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2020 年 7 月 3 日
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 2020 年 7 月 3 日
ok thanks

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 3 日
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 件のコメント
Haleema Ahsan
Haleema Ahsan 2020 年 7 月 4 日
OK thanks

サインインしてコメントする。

その他の回答 (2 件)

Mohanad Alkhodari
Mohanad Alkhodari 2020 年 8 月 11 日
Is it possible to apply mySMOTE on a cell array, say an array of 10 cells, each cell is 5000x12.
let me know.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 11 日
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.

サインインしてコメントする。


Ajay Atwal
Ajay Atwal 2021 年 10 月 21 日
編集済み: Walter Roberson 2021 年 10 月 21 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 21 日
I am not clear how this is an answer to the question that was asked?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by