Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error in Value of 'support' parameter must have two elements.
조회 수: 1 (최근 30일)
이전 댓글 표시
Error:
Error using ksdensity>compute_finite_support (line 181)
Value of 'support' parameter must have two elements.
Code:
clear
tic
disp('--- start ---')
distr='normal';
distr='kernel';
% read data
data = importdata('LDA data.mat')%import the data
features=data(:,1:end-1); %split data without labels
lable=data(:,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
LDA data is a data with seven features to compare and its has a last column as labels.
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!