Error using get for Naive Bayes
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
the cyclist
2013년 1월 25일
Looks like you forget to put a comment character before the line:
>> get predicted output for test set
댓글 수: 3
Venkatesh Deo
2017년 3월 15일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!