求DBSCAN算法的matlab代码!!
各位谁有DB SCAN算法的matlab代码啊?急用啊。:@Q 数据挖掘中聚类算法之DBSCAN算法的matlab实现function =dbscan(X,k,eps)
=size(X);
class=zeros(1,m);
clusterId = 0;
X=;
for i = 1:m
clusterId = clusterId + 1;
if X(i,1) == 0
=expandcluster(i,X,clusterId,eps,k,n);
end
end
class = X(:,1)';
function =expandcluster(index,X,clusterId,eps,k,n)
Di=dist(X(index,(2:n)),X(:,(2:n)));
D = find(Di<eps);
if length(D) < k
X(index,1) = -1; %noise
return;
else
X(index,1) = clusterId;
D(1)=[];
for i=1:length(D)
Dmatrix(i,:)=X(D(i),:);
end
while length(D)~=0
Di=dist(X(D(1),(2:n)),X(:,(2:n)));
Result = find(Di<eps);
if length(Result) > k
for i = 1: length(Result)
if X(Result(i),1) == 0|-1
if X(Result(i),1)==0
D(length(D)+1)=Result(i);
end
X(Result(i),1)=clusterId;
end;
end;
end;
D(1)=[];
end;
end;
%function distan = dist(x,y)
% sum = 0;
%nx = size(x);
%for i = 1:nx
% sum = (x(i)-y(i))^2+sum;
%end
%distan = sqrt(sum)
%............................................
function =dist(i,x)
% function: =dist(i,x)
%
% Aim:
% Calculates the Euclidean distances between i and all objects in x
%
% Input:
% i - an object (1,n)
% x - data matrix (m,n); m-objects, n-variables
%
% Output:
% D - Euclidean distance (m,1)
=size(x);
Di=sqrt(sum((((ones(m,1)*i)-x).^2)'));
if n==1
Di=abs((ones(m,1)*i-x))';
end 这个好像是算一维的吧:@L 再试了一次.原来多了一行注释
Error in ==> dbscan_2>dist at 61
objects in x 请问2楼噪声点是如何处理的:@(
页:
[1]