Borrar filtros
Borrar filtros

Error using get for Naive Bayes

1 visualización (últimos 30 días)
Lester Lim
Lester Lim el 25 de En. de 2013
Comentada: Venkatesh Deo el 15 de Mzo. de 2017
Error using get Too many input arguments.
Error in NaiveBayesClassifier2 (line 82) get predicted output for test set
Code:
% NAIVE BAYES CLASSIFIER
clear
tic
disp('--- start ---')
distr='normal';
distr='kernel';
% read data
data = importdata('White_Wine.xlsx')%import the data
features=data.data.Sheet1(:,1:end-1); %split data without labels
lable=data.data.Sheet1(:,end);
X = features;%Take up to row 11
Y = lable;%Take row 12 which is the label
% Create a cvpartition aka cross validation
c = cvpartition(Y,'holdout',.2);
% Create a training set
x = X(training(c,1),:);
y = Y(training(c,1));
% test set
u=X(test(c,1),:);
v=Y(test(c,1),:);
yu=unique(y);%find the unique elements. The resulting vector yu is sorted in ascending order and its elements are of the same class as y.
nc=length(yu); % number of classes
ni=size(x,2); % independent variables
ns=length(v); % test set
% compute class probability
for i=1:nc
fy(i)=sum(double(y==yu(i)))/length(y);
end
switch distr
case 'normal'
% normal distribution
% parameters from training set
for i=1:nc
xi=x((y==yu(i)),:);
mu(i,:)=mean(xi,1);
sigma(i,:)=std(xi,1);
end
% probability for test set
for j=1:ns
fu=normcdf(ones(nc,1)*u(j,:),mu,sigma);
P(j,:)=fy.*prod(fu,2)';
end
case 'kernel'
% kernel distribution
% probability of test set estimated from training set
for i=1:nc
for k=1:ni
xi=x(y==yu(i),k);
ui=u(:,k);
%fuStruct(i,k).f = ksdensity(xi,ui);
end
end
% re-structure
for i=1:ns
for j=1:nc
for k=1:ni
%fu(j,k)=fuStruct(j,k).f(i);
end
end
%P(i,:)=fy.*prod(fu,2)';
end
otherwise
disp('invalid distribution stated')
return
end
get predicted output for test set
[pv0,id]=max(P,[],2);
for i=1:length(id)
pv(i,1)=yu(id(i));
end
% compare predicted output with actual output from test data
confMat=myconfusionmat(v,pv);
disp('confusion matrix:')
disp(confMat)
conf=sum(pv==v)/length(pv);
disp(['accuracy = ',num2str(conf*100),'%'])
toc

Respuesta aceptada

the cyclist
the cyclist el 25 de En. de 2013
Looks like you forget to put a comment character before the line:
>> get predicted output for test set
  3 comentarios
Lester Lim
Lester Lim el 28 de En. de 2013
Yup, you're right, I changed a few more stuff and it works fine...
Venkatesh Deo
Venkatesh Deo el 15 de Mzo. de 2017
I have put a comment character but it is still not working. What other changes did you make? Can you please help me with those.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by