getting error about wrong input argument
7 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
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.
更多回答(2 个)
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
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
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!