Sequential Clustering Algorithm (BSCA)
显示 更早的评论
I am currently trying to apply Sequential Clustering Algorithm (BSCA) to wine data. And for some reason I am unable to generate any clusters.
Below is my code where the data has first been reduced via PCA. and than BSCA is applied.
Does anyone see anything wrong with the code ?
%Reading in Data
Data = dlmread('wine.csv');
%Extracting data only
X = Data(2:179, 2:14);
%Calculating Eigenvalues and Eigenvectors
[EIGVEC, EIGVAL] = eig(cov(X));
%Reducing the data to 2D
XT = [];
for i=1: length(X)
XT(i,1) = X(i,:) * EIGVEC(:,13);
XT(i,2) = X(i,:) * EIGVEC(:,12);
end
%Prompt for alpha
%prompt2 = 'What is the value for alpha? ';
%alpha = input(prompt2);
function res = BSAS(XT,alpha,q)
N = size(XT,1);
nFeatures = size(XT,2);
labels = zeros(1,N); % zero value indicates unclustered point
m=1;
labels(1)=1;
q=3;
alpha=0.2;
function [d_x_i_C_k, k] = closestcluster(i, labels, XT)
ulab = unique(labels);
if( ulab(1)==0 )
ulab = ulab(2:end);%removes zero value as points are clustered
end
assignclust = [];
for lab = ulab
indv = find(labels==lab);
rep = mean(XT(indv,:), 1)';
d = sqrt(( XT(i,:)' - rep )' * ( XT(i,:)' - rep ) );
assignclust = [assignclust, d];
end
[d_x_i_C_k,mind] = min(assignclust);
k = ulab(mind);%closest cluster
end
for i = 2:N
%find C_k : d(x_i,C_k) = min_{1 <= j <= m} d(x_i,C_j)
[d_x_i_C_k, k] = closestcluster(i, labels, XT );
if((d_x_i_C_k > alpha) & (m < q))
m = m+1;
end
labels(i)=m;
end
res=labels
end
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Cluster Analysis and Anomaly Detection 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!