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에 대해 자세히 알아보기

질문:

2021년 4월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by