在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
%x=[randn(30,2)*.4;randn(40,2)*.5+ones(40,1)*[4 4]]; 测试 数据 或者 可以另外指定 X=[56.70466067,56.70466067,56.70466067,56.70466067,56.70466067,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,21.00466067,22.33256629,22.33256629,23.6604719,24.98837752,24.98837752,24.98837752,26.31628314,26.31628314,26.31628314,26.31628314,27.64418876,27.64418876,27.64418876,27.64418876,27.64418876,28.97209438,28.97209438,28.97209438,28.97209438,28.97209438,28.97209438,28.97209438,30.3,30.3,30.3,30.3,31.62790562,31.62790562,31.62790562,32.95581124,32.95581124,32.95581124,34.28371686,34.28371686,34.28371686,35.61162248,35.61162248,35.61162248,36.9395281,89.10466067,89.10466067,90.43256629,90.43256629,93.08837752,93.08837752,93.08837752,93.08837752,94.41628314,94.41628314,94.41628314,94.41628314,94.41628314,94.41628314,94.41628314,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,98.4,98.4,98.4,98.4,98.4,99.72790562,99.72790562,99.72790562,99.72790562,101.0558112,101.0558112,101.0558112,101.0558112,102.3837169,102.3837169,102.3837169,103.7116225,103.7116225,103.7116225,103.7116225,105.0395281,105.0395281,105.0395281,106.3674337,106.3674337,64.40466067,64.40466067,65.73256629,65.73256629,65.73256629,65.73256629,65.73256629,67.0604719,67.0604719,67.0604719,67.0604719,68.38837752,68.38837752,68.38837752,68.38837752,69.71628314,69.71628314,69.71628314,69.71628314,71.04418876,71.04418876,71.04418876,71.04418876,71.04418876,72.37209438,72.37209438,72.37209438,72.37209438,72.37209438,73.7,73.7,73.7,73.7,75.02790562,75.02790562,75.02790562,75.02790562,76.35581124,76.35581124,76.35581124,77.68371686,77.68371686,48.60466067,49.93256629,49.93256629,49.93256629,49.93256629,49.93256629,49.93256629,49.93256629,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,57.9,57.9,57.9,57.9,57.9,57.9,59.22790562,59.22790562,59.22790562,59.22790562,60.55581124,60.55581124,60.55581124,61.88371686,61.88371686,61.88371686,63.21162248,63.21162248]; X=X(:); Y=[82.04418876,83.37209438,84.7,86.02790562,87.35581124,80.71628314,82.04418876,83.37209438,84.7,86.02790562,87.35581124,88.68371686,90.01162248,78.0604719,79.38837752,80.71628314,82.04418876,83.37209438,84.7,88.68371686,90.01162248,91.3395281,76.73256629,78.0604719,79.38837752,80.71628314,82.04418876,83.37209438,87.35581124,88.68371686,91.12790562,92.45581124,93.78371686,93.78371686,91.12790562,93.78371686,95.11162248,92.45581124,93.78371686,95.11162248,96.4395281,91.12790562,92.45581124,95.11162248,96.4395281,97.76743371,80.50466067,81.83256629,91.12790562,95.11162248,96.4395281,97.76743371,99.09533933,80.50466067,96.4395281,97.76743371,99.09533933,96.4395281,97.76743371,99.09533933,95.11162248,97.76743371,99.09533933,95.11162248,96.4395281,97.76743371,95.11162248,96.4395281,97.76743371,96.4395281,78.02790562,79.35581124,78.02790562,79.35581124,71.38837752,82.01162248,83.3395281,84.66743371,72.71628314,74.04418876,75.37209438,76.7,82.01162248,83.3395281,84.66743371,74.04418876,75.37209438,76.7,78.02790562,79.35581124,83.3395281,84.66743371,85.99533933,74.04418876,75.37209438,76.7,78.02790562,79.35581124,80.68371686,84.66743371,85.99533933,74.04418876,78.02790562,79.35581124,80.68371686,82.01162248,74.04418876,80.68371686,82.01162248,83.3395281,80.68371686,82.01162248,83.3395281,84.66743371,82.01162248,83.3395281,84.66743371,80.68371686,82.01162248,83.3395281,84.66743371,80.68371686,82.01162248,83.3395281,79.35581124,80.68371686,58.34418876,59.67209438,55.68837752,57.01628314,58.34418876,59.67209438,66.31162248,54.3604719,55.68837752,57.01628314,67.6395281,53.03256629,54.3604719,55.68837752,67.6395281,53.03256629,54.3604719,55.68837752,57.01628314,53.03256629,54.3604719,55.68837752,57.01628314,58.34418876,53.03256629,54.3604719,55.68837752,57.01628314,58.34418876,51.70466067,53.03256629,57.01628314,58.34418876,51.70466067,53.03256629,58.34418876,70.29533933,51.70466067,53.03256629,58.34418876,53.03256629,57.01628314,46.27209438,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,40.9604719,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,51.58371686,52.91162248,40.9604719,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,51.58371686,52.91162248,54.2395281,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,51.58371686,52.91162248,54.2395281,55.56743371,42.28837752,43.61628314,44.94418876,46.27209438,47.6,51.58371686,52.91162248,54.2395281,55.56743371,40.9604719,42.28837752,46.27209438,47.6,51.58371686,52.91162248,54.2395281,55.56743371,56.89533933,40.9604719,46.27209438,47.6,54.2395281,55.56743371,56.89533933,39.63256629,40.9604719,54.2395281,55.56743371,39.63256629,40.9604719,55.56743371,52.91162248,54.2395281,55.56743371,54.2395281,55.56743371]; Y=Y(:); point=[X,Y]; % x=[randn(3 , 2)*.4; randn(4,2)*.5 + ones(4,1)*[4 4]]; %[class,type]=dbscan(x,5,[]); %[class,type]=dbscan(x,7,[]); %[class,type]=dbscan(x,10,[]); %[class,type]=dbscan(x,10,2); [class,type]=dbscan(point,3,[]); color_cluster(point,class); % 要可视化聚类结果很简单,实现一个可视化2D数据聚类结果的函数: % ------------- % 输入: % data:数据集 % class:每个数据点的分类,-1表示噪点,分类从1开始 % ------------- function color_cluster(data, class) color_theme = {'ro','rv','bx','ks','r+','go','k*','r+','gv','bs','k+', ... 'gv','gx','bo','kx','rs','gs','b+','ko',... 'rx','g+','bv','kv'}; non_class_color = 'm*'; %噪点 [m, n] = size(data); subplot(1,2,1); %plot(data(:,1),data(:,2),'ko'); plot(data(:,1),data(:,2),'ko'); title('raw data'); subplot(1,2,2); for x = 1:m if class(x) == -1 plot(data(x,1),data(x,2) ,non_class_color) else plot(data(x,1),data(x,2) ,cell2mat(color_theme(class(x)))) end hold on; end title('result'); % % 我们测试一下: % % % % x=[randn(30,2)*.4;randn(40,2)*.5+ones(40,1)*[4 4]]; % % [class,type]=dbscan(x,5,[]); % % color_cluster(x,class); function [D]=dist(i,x) % function: [D]=dist(i,x) % % Aim: % Calculates the Euclidean distances between the i-th object 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) [m,n]=size(x); D=sqrt(sum((((ones(m,1)*i)-x).^2)')); if n==1 D=abs((ones(m,1)*i-x))'; end function [Eps]=epsilon(x,k) % Aim: % Analytical way of estimating neighborhood radius for DBSCAN % % Input: % x - data matrix (m,n); m-objects, n-variables % k - number of objects in a neighborhood of an object % (minimal number of objects considered as a cluster) [m,n]=size(x); Eps=((prod(max(x)-min(x))*k*gamma(.5*n+1))/(m*sqrt(pi.^n))).^(1/n); % % 一、基于密度的聚类算法的概述 % % 最近在Science上的一篇基于密度的聚类算法《Clustering by fast search and find of density peaks》引起了大家的关注(在我的博文“论文中的机器学习算法——基于密度峰值的聚类算法”中也进行了中文的描述)。于是我就想了解下基于密度的聚类算法,熟悉下基于密度的聚类算法与基于距离的聚类算法,如K-Means算法之间的区别。 % % 基于密度的聚类算法主要的目标是寻找被低密度区域分离的高密度区域。与基于距离的聚类算法不同的是,基于距离的聚类算法的聚类结果是球状的簇,而基于密度的聚类算法可以发现任意形状的聚类,这对于带有噪音点的数据起着重要的作用。 % % 二、DBSCAN算法的原理 % % 1、基本概念 % % DBSCAN(Density-Based Spatial Clustering of Application with Noise)是一种典型的基于密度的聚类算法,在DBSCAN算法中将数据点分为一下三类: % % 核心点。在半径Eps内含有超过MinPts数目的点 % % 边界点。在半径Eps内点的数量小于MinPts,但是落在核心点的邻域内 % % 噪音点。既不是核心点也不是边界点的点 % % 在这里有两个量,一个是半径Eps,另一个是指定的数目MinPts。 % % 一些其他的概念 % % Eps邻域。简单来讲就是与点的距离小于等于Eps的所有的点的集合,可以表示为。 % % 直接密度可达。如果在核心对象的Eps邻域内,则称对象从对象出发是直接密度可达的。 % % 密度可达。对于对象链:,是从关于Eps和MinPts直接密度可达的,则对象是从对象关于Eps和MinPts密度可达的。 % % 2、算法流程 % ------------------------------------------------------------------------- % Function: [class,type]=dbscan(x,k,Eps) % ------------------------------------------------------------------------- % Aim: % Clustering the data with Density-Based Scan Algorithm with Noise (DBSCAN) % ------------------------------------------------------------------------- % Input: % x - data set (m,n); m-objects, n-variables % k - number of objects in a neighborhood of an object % (minimal number of objects considered as a cluster) % Eps - neighborhood radius, if not known avoid this parameter or put [] % ------------------------------------------------------------------------- % Output: % class - vector specifying assignment of the i-th object to certain % cluster (m,1) % type - vector specifying type of the i-th object % (core: 1, border: 0, outlier: -1) % ------------------------------------------------------------------------- % Example of use: % x=[randn(30,2)*.4;randn(40,2)*.5+ones(40,1)*[4 4]]; % [class,type]=dbscan(x,5,[]) % clusteringfigs('Dbscan',x,[1 2],class,type) % ------------------------------------------------------------------------- % ------------------------------------------------------------------------- % Input: % x - data set (m,n); m-objects, n-variables % k - number of objects in a neighborhood of an object % (minimal number of objects considered as a cluster) % Eps - neighborhood radius, if not known avoid this parameter or put [] % ------------------------------------------------------------------------- function [class,type]=dbscan(x,k,Eps) [m,n]=size(x); %得到数据的大小 if nargin<3 | isempty(Eps) [Eps]=epsilon(x,k); % ?? end x=[[1:m]' x]; [m,n]=size(x); %重新计算数据集的大小 type=zeros(1,m); %用于区分核心点1,边界点0和噪音点-1 no=1; %用于标记类 touched=zeros(m,1); %用于判断该点是否处理过,0表示未处理过 %% 对每一个点进行处理 for i=1:m %找到未处理的点 if touched(i)==0; ob=x(i,:); D=dist(ob(2:n),x(:,2:n)); %取得第i个点到其他所有点的距离 ind=find(D<=Eps); %找到半径Eps内的所有点 %% 区分点的类型 %边界点 if length(ind)>1 & length(ind)<k+1 type(i)=0; class(i)=0; end %噪音点 if length(ind)==1 type(i)=-1; class(i)=-1; touched(i)=1; end %核心点(此处是关键步骤) if length(ind)>=k+1; type(i)=1; class(ind)=ones(length(ind),1)*max(no); % 判断核心点是否密度可达 while ~isempty(ind) ob=x(ind(1),:); touched(ind(1))=1; ind(1)=[]; D=dist(ob(2:n),x(:,2:n)); %找到与ind(1)之间的距离 i1=find(D<=Eps); if length(i1)>1 %处理非噪音点 class(i1)=no; if length(i1)>=k+1; type(ob(1))=1; else type(ob(1))=0; end for i=1:length(i1) if touched(i1(i))==0 touched(i1(i))=1; ind=[ind i1(i)]; class(i1(i))=no; end end end end no=no+1; end end end % 最后处理所有未分类的点为噪音点 i1=find(class==0); class(i1)=-1; type(i1)=-1;
只标记分类 不绘图 %只筛选标记 不作绘图 X=[56.70466067,56.70466067,56.70466067,56.70466067,56.70466067,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,58.03256629,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,59.3604719,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,60.68837752,21.00466067,22.33256629,22.33256629,23.6604719,24.98837752,24.98837752,24.98837752,26.31628314,26.31628314,26.31628314,26.31628314,27.64418876,27.64418876,27.64418876,27.64418876,27.64418876,28.97209438,28.97209438,28.97209438,28.97209438,28.97209438,28.97209438,28.97209438,30.3,30.3,30.3,30.3,31.62790562,31.62790562,31.62790562,32.95581124,32.95581124,32.95581124,34.28371686,34.28371686,34.28371686,35.61162248,35.61162248,35.61162248,36.9395281,89.10466067,89.10466067,90.43256629,90.43256629,93.08837752,93.08837752,93.08837752,93.08837752,94.41628314,94.41628314,94.41628314,94.41628314,94.41628314,94.41628314,94.41628314,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,95.74418876,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,97.07209438,98.4,98.4,98.4,98.4,98.4,99.72790562,99.72790562,99.72790562,99.72790562,101.0558112,101.0558112,101.0558112,101.0558112,102.3837169,102.3837169,102.3837169,103.7116225,103.7116225,103.7116225,103.7116225,105.0395281,105.0395281,105.0395281,106.3674337,106.3674337,64.40466067,64.40466067,65.73256629,65.73256629,65.73256629,65.73256629,65.73256629,67.0604719,67.0604719,67.0604719,67.0604719,68.38837752,68.38837752,68.38837752,68.38837752,69.71628314,69.71628314,69.71628314,69.71628314,71.04418876,71.04418876,71.04418876,71.04418876,71.04418876,72.37209438,72.37209438,72.37209438,72.37209438,72.37209438,73.7,73.7,73.7,73.7,75.02790562,75.02790562,75.02790562,75.02790562,76.35581124,76.35581124,76.35581124,77.68371686,77.68371686,48.60466067,49.93256629,49.93256629,49.93256629,49.93256629,49.93256629,49.93256629,49.93256629,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,51.2604719,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,52.58837752,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,53.91628314,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,55.24418876,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,56.57209438,57.9,57.9,57.9,57.9,57.9,57.9,59.22790562,59.22790562,59.22790562,59.22790562,60.55581124,60.55581124,60.55581124,61.88371686,61.88371686,61.88371686,63.21162248,63.21162248]; X=X(:); Y=[82.04418876,83.37209438,84.7,86.02790562,87.35581124,80.71628314,82.04418876,83.37209438,84.7,86.02790562,87.35581124,88.68371686,90.01162248,78.0604719,79.38837752,80.71628314,82.04418876,83.37209438,84.7,88.68371686,90.01162248,91.3395281,76.73256629,78.0604719,79.38837752,80.71628314,82.04418876,83.37209438,87.35581124,88.68371686,91.12790562,92.45581124,93.78371686,93.78371686,91.12790562,93.78371686,95.11162248,92.45581124,93.78371686,95.11162248,96.4395281,91.12790562,92.45581124,95.11162248,96.4395281,97.76743371,80.50466067,81.83256629,91.12790562,95.11162248,96.4395281,97.76743371,99.09533933,80.50466067,96.4395281,97.76743371,99.09533933,96.4395281,97.76743371,99.09533933,95.11162248,97.76743371,99.09533933,95.11162248,96.4395281,97.76743371,95.11162248,96.4395281,97.76743371,96.4395281,78.02790562,79.35581124,78.02790562,79.35581124,71.38837752,82.01162248,83.3395281,84.66743371,72.71628314,74.04418876,75.37209438,76.7,82.01162248,83.3395281,84.66743371,74.04418876,75.37209438,76.7,78.02790562,79.35581124,83.3395281,84.66743371,85.99533933,74.04418876,75.37209438,76.7,78.02790562,79.35581124,80.68371686,84.66743371,85.99533933,74.04418876,78.02790562,79.35581124,80.68371686,82.01162248,74.04418876,80.68371686,82.01162248,83.3395281,80.68371686,82.01162248,83.3395281,84.66743371,82.01162248,83.3395281,84.66743371,80.68371686,82.01162248,83.3395281,84.66743371,80.68371686,82.01162248,83.3395281,79.35581124,80.68371686,58.34418876,59.67209438,55.68837752,57.01628314,58.34418876,59.67209438,66.31162248,54.3604719,55.68837752,57.01628314,67.6395281,53.03256629,54.3604719,55.68837752,67.6395281,53.03256629,54.3604719,55.68837752,57.01628314,53.03256629,54.3604719,55.68837752,57.01628314,58.34418876,53.03256629,54.3604719,55.68837752,57.01628314,58.34418876,51.70466067,53.03256629,57.01628314,58.34418876,51.70466067,53.03256629,58.34418876,70.29533933,51.70466067,53.03256629,58.34418876,53.03256629,57.01628314,46.27209438,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,40.9604719,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,51.58371686,52.91162248,40.9604719,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,51.58371686,52.91162248,54.2395281,42.28837752,43.61628314,44.94418876,46.27209438,47.6,48.92790562,50.25581124,51.58371686,52.91162248,54.2395281,55.56743371,42.28837752,43.61628314,44.94418876,46.27209438,47.6,51.58371686,52.91162248,54.2395281,55.56743371,40.9604719,42.28837752,46.27209438,47.6,51.58371686,52.91162248,54.2395281,55.56743371,56.89533933,40.9604719,46.27209438,47.6,54.2395281,55.56743371,56.89533933,39.63256629,40.9604719,54.2395281,55.56743371,39.63256629,40.9604719,55.56743371,52.91162248,54.2395281,55.56743371,54.2395281,55.56743371]; Y=Y(:); point=[X,Y]; z=dbscan(point,7,3); %看z的具体值分为1,2,3,4而-1为异常值 function [D]=dist(i,x) % function: [D]=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) [m,n]=size(x); D=sqrt(sum((((ones(m,1)*i)-x).^2)')); if n==1 D=abs((ones(m,1)*i-x))'; end function [Eps]=epsilon(x,k) % Function: [Eps]=epsilon(x,k) % % Aim: % Analytical way of estimating neighborhood radius for DBSCAN % % Input: % x - data matrix (m,n); m-objects, n-variables % k - number of objects in a neighborhood of an object % (minimal number of objects considered as a cluster) % % Output: % Eps - estimated neighborhood radius [m,n]=size(x); Eps=((prod(max(x)-min(x))*k*gamma(.5*n+1))/(m*sqrt(pi.^n))).^(1/n); %............................................ function [class,type]=dbscan(x,k,Eps) % Function: [class,type]=dbscan(x,k,Eps) % % Aim: % Clustring the data with Density Based Scan Algorithm with Noise (DBSCAN) % % Input: % x - data set (m,n); m-objects, n-variables % k - number of objects in a neighborhood of an object % (minimal number of objects considered as a cluster) % Eps - neighborhoog radius, if not known put [] % % Output: % class - vector specifying belongingness of the i-th object to certain cluster (m,1) % type - vector specifying type of the i-th object (core: 1, border: 0, outlier: -1) % % Example of use: % x=[randn(30,2)*.4;randn(40,2)*.5+ones(40,1)*[4 4]]; % [class,type]=dbscan(x,5,[]) % % References: % [1] M. Ester, H. Kriegel, J. Sander, X. Xu, A density-based algorithm for discovering % clusters in large spatial databases with noise, proc. 2nd Int. Conf. % on Knowledge Discovery and Data Mining, Portland, OR, 1996, p. 226, % available from: www.dbs.informatik.uni-muenchen.de/cgi-bin/papers?query=--CO % [2] M. Daszykowski, B. Walczak, D. L. Massart, Looking for Natural Patterns in Data. % Part 1: Density Based Approach, Chemom. Intell. Lab. Syst. 56 (2001) 83-92 % Michal Daszykowski % Department of Chemometrics % The University of Silesia % 9 Szkolna Street % 40-006 Katowice, Poland [m,n]=size(x); if nargin<3 | isempty(Eps) [Eps]=epsilon(x,k); end x=[[1:m]' x]; [m,n]=size(x); type=zeros(1,m); no=1; touched=zeros(m,1); for i=1:m if touched(i)==0; ob=x(i,:); D=dist(ob(2:n),x(:,2:n)); ind=find(D<=Eps); if length(ind)>1 & length(ind)<k+1 type(i)=0; class(i)=0; end if length(ind)==1 type(i)=-1; class(i)=-1; touched(i)=1; end if length(ind)>=k+1; type(i)=1; class(ind)=ones(length(ind),1)*max(no); while ~isempty(ind) ob=x(ind(1),:); touched(ind(1))=1; ind(1)=[]; D=dist(ob(2:n),x(:,2:n)); i1=find(D<=Eps); if length(i1)>1 class(i1)=no; if length(i1)>=k+1; type(ob(1))=1; else type(ob(1))=0; end for i=1:length(i1) if touched(i1(i))==0 touched(i1(i))=1; ind=[ind i1(i)]; class(i1(i))=no; end end end end no=no+1; end end end i1=find(class==0); class(i1)=-1; type(i1)=-1; %........................................... 最后z分为5类值:1,2,3,4,5,-1 其中-1为异常值
另外一种DBSCAN 聚类 % % Copyright (c) 2015, Yarpiz (www.yarpiz.com) % All rights reserved. Please read the "license.txt" for license terms. % % Project Code: YPML110 % Project Title: Implementation of DBSCAN Clustering in MATLAB % Publisher: Yarpiz (www.yarpiz.com) % % Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team) % % Contact Info: [email protected], [email protected] clc; clear; close all; %% Load Data X=[0.851403135086569,-0.473129980972481;-0.0143385521233045,0.689712419407323;-0.0225941463131059,-0.284256368553826;-0.0610040966320611,-1.25288241358493;1.80117233191458,-0.0439530948272436;-0.231990584409464,-0.432152258671540;0.451005664109405,0.509448291585219;-0.332307442473074,0.357188901599257;1.21156610943639,-0.982158613685041;-0.313355175598868,1.14892742489430;-0.926445289673896,0.434611267965341;1.01517568797153,-1.08298578575233;-0.325034731469111,0.241466601791346;-0.0330343244242803,-0.343982552671932;-0.674309830867955,0.783755234640380;-0.328543772237157,-0.533932267968002;-0.991272497729558,-1.28828476707858;-0.440599925733113,0.966849073124444;-0.385467065955120,-0.863615619096165;0.468760528141179,-0.130974595338288;-0.0940298788944022,-0.368448959656644;0.278128169428504,0.0166977609109131;0.756870976420947,-2.08238210433868;-1.03251448268113,-1.40409663914452;-0.0335361385536346,0.456282760690612;0.908341594657170,0.163245561731714;-1.12184369860605,0.0218630545204664;0.403914974186831,-1.24500829463461;1.63585886336799,0.520462800581572;0.804227563945955,-1.59420465573869;-0.0795035652250097,-0.567210793390362;-0.426852729414960,0.0498663598354053;0.167097417826316,0.140841091737349;0.232983900083107,-0.116110172310699;-0.626430792550341,0.0904126767681207;1.36396927463365,0.830663286973774;0.650981874069926,-1.04648165259711;-0.115120160954915,-0.771940334716404;0.000405935112662872,0.743807957304745;-1.52328631722222,0.140467461060478;1.34777598282994,-0.798480973347104;-0.812202840767802,0.0577231924693656;1.33008936403371,-1.23738040720206;-1.30621641686816,0.646472113166677;0.507031978133958,0.444564961953638;-0.0322931942188008,-0.551053273687477;0.546438378197356,0.267465545514150;-0.118587032785411,1.27643799271765;-0.626041951213916,-0.0953139899785633;0.453755347485846,0.287206842874819;0.969664605026431,0.538148559179079;1.25290832188369,0.724626696901346;-0.593143094274061,1.31382181318861;-1.42222383795303,0.893456133536546;-0.0928269476242106,1.40114298326168;1.43240523230272,0.589780856526984;0.448632390674321,0.360859279197181;-0.0132145166157090,-0.337315401470054;0.160810166073833,0.546135033243474;-0.584361142505334,-1.55878801228024;-0.617291333724175,0.699232094934682;0.514928251906051,-1.49364827722076;0.0138635993228995,-0.647257097943863;1.96784561483740,-0.0572828698003273;0.516160021572451,-0.797145733329533;1.29097894351733,-1.48178673794837;1.04574463990739,0.622207181516242;-0.541342049995913,1.00989228438232;0.266109461297069,-1.09642417641248;-0.321706991751831,0.638577488777399;1.40571486588374,1.90425418037697;-0.789699946866524,1.08970735885582;0.138634129269004,-0.815238127350002;-0.897150307330400,0.718335930712740;-1.04743297542305,1.09057535383106;-0.124584470693613,0.319191450115608;0.509434596965920,-0.178013654528075;-0.241363502480452,-1.58204435460770;-0.393667878380026,-0.767655347278958;1.41862767907158,-0.0178488111516978;0.673472141925565,-1.42567312431223;-0.890841125358596,0.637666206759049;0.423864333494803,0.475019480775181;-0.259991105155046,-0.0106233858636353;-0.130087061984227,0.197067831310703;1.19561284700488,0.364166809590991;-1.94965957820543,-0.952605628220473;0.291751861163691,0.666932654967058;1.58444696348414,1.17316410607547;-0.640143553705955,-0.735492050622295;0.602856706078690,0.622660894273971;-0.502034040236210,-0.230244099116707;0.704387852343892,-0.232939843371759;-1.28997533357924,-0.300450201199654;-1.13409261203568,-0.490617621675583;-0.702344450839358,-0.0858600048291331;0.871107465909712,-1.06496578026199;0.897243949885602,-0.438976228624805;-0.527373491940105,0.0394921101386377;-1.14650801804505,1.26512119754662;0.567918245792361,-0.355357276897022;1.15799623581136,-0.776967887125450;-0.934896082923188,-0.521467216013195;-0.129228664439574,-1.39700206278629;0.508766290448633,-0.598958439389555;-0.198796871979583,-0.602536401135011;-0.247375107058653,0.304326391318031;0.876370109529104,0.534235905078014;0.432554038721506,-0.243420716467233;-1.38748303505948,1.27511746693595;-0.446355670979072,-2.26407483829053;1.74627555936846,-1.36485412954923;-0.513761803336968,0.234744127439090;0.795099935849500,0.717521318539757;0.268417366459686,0.626554948757433;0.180576025574037,1.20693420414650;-0.704119098752651,0.666619237836174;0.744820330758183,-0.711729013772122;-0.500694806059865,-1.36166070617287;1.98378777785228,-0.0250690701874545;-0.634674250424264,0.313592259485765;0.0941200155413062,-0.126469434998702;-0.428735988318612,-1.63509566972446;0.128926771644097,0.109926281657495;0.384251308255014,1.13295292685555;-1.13721569931103,-1.79000384345919;0.0175573798653556,-0.643224054595771;0.211619308151105,0.989585510347632;-0.743071682153239,-1.45911124668968;0.835069984028554,0.464020867163188;0.478507287015187,-0.433824957882879;0.813119510272553,0.214205750341315;0.476243613033038,1.46321655548944;-0.0955926750271805,0.621274368658119;-1.22878301784097,-0.115784674252286;-0.150696717394072,0.339924347062621;-0.980360168187952,-0.297085545024994;0.161107001501499,-0.0529868329891070;-0.401711734164833,0.0671615148364457;-0.0292322919416246,-0.414389584185193;0.0434778178816344,-0.0452690528340896;1.79123075811061,0.810392508284597;-0.500551745139609,0.513938176603306;0.885723973156126,-0.386793228061598;-0.288152928860950,-1.05897710421477;-1.00373283327072,-0.392359498102900;0.924633473660674,-0.800384621884143;-1.38188545045619,-0.687715907101494;0.409370162308959,1.21092748761916;-0.812525998614526,0.0610026105461838;0.201769247353032,-1.62185597672931;1.86232458127952,-1.47419168040894;1.68275049278576,0.643177160520134;0.483290009601737,0.185010291331965;0.469852808825871,0.431488159866035;-0.233244138807079,1.31603779047937;-0.303534995820002,-0.406236806290399;0.699057226112228,-0.206808867082432;-0.755932771536502,-0.716841824740523;-0.137295699764704,-1.04540186189125;1.81320616882662,-0.790820320457135;0.0663496042964903,0.343635868655767;-0.359594171255293,0.746750480950846;-1.66638967732583,-0.425965671704383;-0.191810815426262,-1.17106001084320;-0.316826244488455,0.561078069646286;-0.335338990979809,-1.65274445644264;-0.375520307167807,-0.548409685384089;0.0185540177144707,-1.13417378260840;1.01207606935099,-0.617255757867700;-0.876426201835071,-0.203088190747984;0.108300408901506,1.36232687340689;0.00218789417860655,0.695456065780278;-0.939975385263652,-0.358470360918045;1.30283596179283,0.00267788353485366;1.19603735000728,-1.18662920393894;0.598883652191289,-0.169819826784064;-0.227404005546397,0.102797604353177;-0.875802934176858,-0.595126731038317;0.447302960079113,-0.281221128380804;0.512885466919188,0.575249632749204;0.0445923439331762,-1.12672954386968;-1.12011899575360,0.914694885309904;1.36127896848250,1.46091988913459;-1.15032139672951,-0.500652316493059;0.302395012812372,0.198998709083927;-0.228376674204686,-0.0186532769465762;-2.26413788734386,-0.154674932641973;0.0983245448419042,-0.890502758476620;-0.743535328260789,-0.355220458591626;0.775225407152359,0.529698254484606;0.521397000541911,0.603364947325844;-1.33994728142537,-0.751588887188293;-0.354164324053830,0.102188136882157;0.132186983720347,0.430356757002679;0.165259985348386,1.07862563293371;1.14482005993569,0.402539428679472;-0.785735632998866,-1.63496435074993;0.0305706048247976,-0.530333248034426;0.118639963580212,-0.571820153410517;-0.708806171239830,-0.353386333407913;0.909623574333429,-0.363392676410011;-1.10965697438413,0.817111889815803;0.465805598398977,0.0654757013819209;-0.698555330882680,1.55004778736595;0.396236837989394,0.339028132934596;-0.763661645259305,-0.195025346183613;0.245499580353500,0.644082235986448;-1.70207371425037,-0.477237182692036;-1.19117904166530,-0.417016710158252;-0.526564117066081,-0.111032890656210;0.138005640318645,-1.06440514097205;0.116594351703247,-0.348021005077340;-0.0323049001246057,-0.775814564535736;-0.707721487017779,-0.649220376257501;-0.389099505816314,-0.426245466023355;-1.19799491670534,-1.28984100067544;-1.01485068781512,-0.413565839741775;-2.12683641724198,0.00362117099480105;0.145077320240351,1.23746001460342;0.112229210182464,1.11332671975778;0.180481314333538,-0.208473472928401;-0.965537312959112,-0.160568424180516;0.255735457620873,0.965017647824803;0.289719627084579,0.206688640761284;0.145988737820473,-0.923715930413243;1.98054396804911,-0.306124591968637;-0.726560017113136,-0.264835789095823;-0.155557014812085,-1.12373002084361;-1.08717741998012,-0.210611178690292;0.989026334905811,1.28644762900638;1.33807226034067,0.647669477625713;-1.25769047450349,0.971656021885114;-0.105395326725074,0.0690125994803742;1.57600973591844,0.0142522155913231;0.147960545790889,0.891200246842153;0.0446741282095810,-0.275847064332583;0.492601907814685,0.255595112914095;0.545345497350113,-0.631761223068718;-0.885992564081990,-1.54764047690139;0.209205778414068,-0.449855614615190;-0.428171676791103,0.146537871600221;-1.19137157474086,0.798697925875255;-0.947249746787464,0.108196522410801;0.0314690032549208,-1.05089134794703;-0.237987409367987,0.634511453573731;-0.902049700761316,0.00845485578182690;0.437207954411150,-0.526944288805728;-0.657877654237169,-0.519441745264334;0.930453813734077,-0.988775144907727;0.701439005718088,0.225060453653785;-0.284461316050268,0.511329815449617;0.726855088044256,0.240910143000375;0.185428768363872,0.554983168717347;-0.130964505263922,0.0885322851200708;0.343702668273201,0.0636738239952805;-0.210592474865712,-0.286708312869680;-1.08029747648790,1.31990312838720;0.692157298389358,-0.895556720798231;0.288979146079023,0.389798583310157;-0.516321761032473,1.00109889466978;0.227724907151555,0.650379357261649;0.0308171633511083,0.809293140380204;-1.23333715004137,-0.0467919803568150;-1.72837937179382,-0.458197975887880;-0.160147356374789,-0.0310364244979466;-1.98027310513409,0.926394178157440;0.161413729666722,0.562218086877871;-1.16038059701224,-0.429280384760805;0.243490693023694,-1.70701032072271;-1.00808682338823,0.112143540986397;-0.980047083317170,1.51505863657676;1.02844471929902,0.615765847705199;-0.0274402255009172,1.42270113928403;-0.897925206209551,0.618597718562649;0.140286595647992,-1.27169769493602;-0.313272568827778,-0.357696976281336;-0.363214318402778,0.237650877763148;-0.259300390824598,-0.665663616336808;-1.79594072283090,0.0451957847258865;-1.31965564288286,-1.02493798080317;-1.08181631612099,0.342674113967219;0.403951542939906,1.03186526484819;-0.0778535053100324,-0.900682618576575;0.258502322594074,0.289636288963213;-0.655391817580893,0.466489394151992;-1.35452942120581,-0.0418754048760190;0.311132317834387,-0.187851172510864;0.906050267390256,-0.617103881691148;-0.124630635141358,-0.132325570107312;0.925185020139369,-0.573003212848472;0.148812719596386,0.292749475573647;0.985151590740551,-1.24999632364471;-0.581001074657753,-1.48426681642536;-0.501020971654043,1.69177648437272;0.371547688531884,-0.437693390364218;0.988095322954662,-0.0879948893747378;0.121298959265064,-0.198744712866603;0.887642438363742,-0.788460574647595;-0.0457735631063480,1.35332211051316;-1.40752089456371,0.769038924727587;-1.01252771389921,-0.355116255672589;0.547883504573530,0.509816562921687;0.611165500676238,0.613124562309603;-0.0119514372028091,-0.748473658670974;-0.233059936855048,1.22489739639392;0.390311659722373,0.334572544928212;-0.603423173446973,0.832584814357223;-0.0144740780100697,0.0436679647872782;-1.03832858877526,0.475498022444234;0.301811834186723,-1.20144297957673;-1.22405364178429,1.11612764309048;0.286334721806747,-1.72072610755022;1.12474539695135,-1.28280237921981;0.577468857193040,0.0637225761001807;-0.501303417781672,-0.719976066042957;-0.626138197461824,0.0682986788401482;-0.268874805682798,0.708886270533125;2.06754664154143,0.672240183289361;1.49233173597889,0.353691023550336;0.256879352781016,0.581784465102164;0.172512445812608,0.661587059442096;0.309431745524189,0.674977907424030;1.61699294794098,0.624278931007399;0.290974673668630,0.758916898522239;-0.257503465414993,0.536412562702471;-1.21593287418458,0.542645059345448;1.30260058914871,0.139305417472207;-0.0457031470538969,0.0123548578169672;0.293727678940304,0.0577349470882062;0.624474038903530,-0.161885032793345;-1.25297481829255,1.88688811256307;0.726254609428325,2.06914430419161;0.322767052970911,-0.547535451610764;1.49954596821641,0.619651294189132;-0.469883316352418,-0.419660970848882;-0.570817054505356,-0.101542300710940;2.04363476084141,0.590400222793054;0.253286112898015,0.584363205016504;0.405379682116085,1.04545562523930;0.610892327830635,-1.43420845986422;-0.918012045486365,-1.46733131156152;0.689061838189169,0.970313638863159;0.883171311012425,-0.153232801979999;-0.859836253888845,0.521795040124635;0.715578756624138,1.29077975190934;-1.29361857696713,-0.335099490963216;0.267679212516649,-0.408678402572121;0.413024181704813,-0.112501923280020;-1.50587448728282,-0.289166703089680;-0.202002142776031,1.29224356388910;-0.959194830835450,-0.793319155601430;0.418565282728189,-0.923483663503886;0.198246915782785,0.186560174972332;0.00129122963879560,-0.0289161225675570;-0.288552147123351,-0.520920320030107;-0.572006649839543,-0.0737259613009863;-0.719324134512467,1.22596629733364;-0.133388714044536,-0.132359296963796;-0.559824118762576,1.35923147038287;-1.74481441278829,-0.429764793022444;-1.00915367421324,1.18882766232097;-0.452007628823371,0.0481212629140170;-1.05930563002742,1.16737604344696;0.416741208367106,0.446044724208292;-0.481551073849327,1.35277324964743;0.484457889379757,-0.182264899279516;-0.608291197454682,0.442777685817525;-0.188059439608459,0.711403215695584;-0.202736286627045,0.428133208286628;0.345935463529611,-1.25644349611763;-0.213558393658958,-0.614394002341074;0.795063773939893,0.932146415148329;-2.03456341253553,-1.15127671577875;0.392131219480001,-2.86956517472613;1.52846314674513,-0.698857767284948;0.231447090332427,0.857666153778464;0.0254736815851833,-0.886602410897202;-0.112144350834825,0.797441286789398;0.486239077299172,0.0308449908745703;0.152639474310169,0.291058179728814;0.697041140314914,0.146760088034139;0.921919254555835,-1.53564033242104;-1.09162091416072,-0.725032441658203;0.461230868982243,-0.702632458982111;-0.762308721681700,0.188661984919519;-0.0267861502951600,0.336300135519108;-0.317380130019386,0.414575239434657;0.257847170699358,-1.13312527493475;1.58538948411166,0.939676588366702;0.239705332771800,0.298375868807153;-0.875877828834379,0.931497210530428;-0.125937469389768,0.161502431711115;-1.18799027046427,-0.593923848324424;-0.348282147403970,1.57621031070866;-0.551207522515835,2.31233012385174;1.58850178215842,-1.16939468492785;-0.318827958684215,0.341886565617294;0.301667399945684,-0.218031945425233;0.805420696145366,0.184675366691312;-0.646766502589300,0.303745780452822;-0.289660794190369,-1.04683232142510;-1.46701127659970,0.339954975780579;-0.851434753950484,-0.109922143626028;0.400358554065480,-0.278374258150974;0.553882718769781,-1.29083464321456;-0.291817761095059,0.210482284590927;-0.618010502756651,-0.115809039528780;0.143292539534772,-0.391567904466992;0.125998843916864,0.334489269100786;-0.146001925395615,0.910323744381836;0.648806377178966,-0.320570784154905;-0.699682482191375,-0.119226026059734;-0.157104294509116,-0.931339297931336;0.0801828253410317,0.454005866908870;1.92052139372240,0.372033256350640;0.979463158436656,0.118935877854764;-0.000779447856084988,0.654077297754245;-0.332578370370696,-0.0148867376913024;-0.902322915907549,0.768120682832945;0.260221380036246,0.745567136069740;-0.708035228625356,1.30252566337368;-0.151612994523752,-0.0695820881429840;-2.32219452210224,-0.728600894874358;0.600720928289906,-1.19500532344365;-0.0753290178918703,-0.327310959674125;0.127300712512011,0.362251709096736;-0.206313491702423,0.224142564975490;1.08941378447522,-1.14870416664216;-0.102157462569054,1.12114084135180;0.432081199693788,-1.69271069286813;0.131215057926959,0.268710334026202;0.175419184722903,1.94134917319629;0.259695458407081,0.0231250622928163;-0.530654900177502,0.978594476486771;0.908152844187588,0.143289020169843;-1.78346757177442,-0.523586451447988;0.242986393359016,-0.308389229042762;-0.236019282244355,-0.342654640298142;0.286981789554352,0.985437071726386;0.107357246650536,-1.27779884209298;-0.291088955200243,-0.782237538189678;-1.48838869390190,0.610480261635520;-0.290428641904365,0.449393032743737;-0.124246773574067,0.524294208542101;-1.10911309794130,-0.922642789925004;-0.266615122954708,0.0436078655289662;0.0674109443499525,-1.30356408272809;0.731210224052585,-0.299424682168368;-0.0783140011179236,0.984867530517952;-0.0671132912319112,0.134076483025846;-0.364067122671229,-0.722874921131597;1.51439439837422,-0.0771940802024117;-0.996239031400006,-0.247085458237878;0.781994779770694,-0.635290896163928;-0.415136775403776,1.02903264950054;0.261975576403215,0.227241434864270;0.105179902224613,-1.30655136783898;0.131078831076714,1.19726898912671;-0.572431312697528,-0.517738110135124;0.761193115065827,-0.151528430075772;-0.700787892018522,-0.125817925825309;-0.710523515085594,-1.14743494048308;0.271725446742974,0.772344368086419;-1.00885937023322,1.50930568190961;0.634348610923551,-0.546333228806681;-0.968929647938074,0.975795787080948;-0.213074124452758,0.406380732935223;-0.760407627561462,-0.462600816382117;0.0227641270806949,0.499118388541767;-0.959163904961547,-1.27371697507166;-0.181799908314369,-0.317001719956157;1.92695528998332,-0.245442915649609;-0.467693995266174,-1.07492941887782;-0.481078749641947,0.0480267761530564;2.58614731615451,-0.221955824066255;0.516511860243649,-0.919767943126101;-0.938728713659267,-0.496212780312738;-2.00052142463382,-0.867698132557368;-0.307549905884066,0.506046051241367;0.891452945277505,0.867061423703767;0.0225117147340936,0.596189724647175;-0.00284388720760158,0.938964136512649;0.542444705306723,0.930504333514282;-0.398606019904522,-0.836212527633248;0.624134747649245,-0.892087592670498;0.174325534082661,-0.399241410096260;0.578516076217968,2.27286393319520;0.368006030992534,0.970820131777525;-0.743635644009496,0.404244454419487;-0.0629951619608784,1.32415709008755;-0.401514889609861,0.0470256506472721;-1.54759474103388,-0.316654798982184;1.54605390698592,-0.233088332737206;0.518459980080741,0.326038971090102;-0.0484911809391796,0.568328506879675;-0.463899973717016,-0.265386373267296;-0.466383396849741,-0.145294301176185;0.160056442839050,0.199649543916765;-0.577544831943327,-0.348426759562846;2.50636262096189,-1.89942385825356;1.87962131484011,2.78971840907837;2.17528438813680,-3.10117825885630;3.24234894810685,2.24978693293942;2.42327181877812,1.90342341110681;3.29283973093715,2.08931278675576;3.40979093479647,1.68208811315795;1.34004449580202,3.49243122026193;0.503016464294754,-3.24483387006166;0.331608982467335,-3.67672234296917;0.182200361178451,-3.09145137216155;3.85938766092990,-0.978023269732328;2.44181487598509,3.04044056846152;0.594531454804245,3.79943389075634;3.59697018928767,-0.615183209784243;1.12086249976746,-3.50908755094999;0.603439893242363,3.40872455596613;1.34071004930712,3.58894051518642;3.59293385548593,-0.442464674327149;3.87903481973303,-0.164894281347844;2.66514757497131,1.50939335867939;0.998144879389831,3.51845333774610;3.96432503009658,0.0931124909736951;2.19640125460340,2.16547446521701;1.80275453311028,-2.59823243798084;2.68692704734840,2.47216499010988;3.21964781432772,0.370271472285136;1.53849476488092,-3.42399709316578;3.26764851357532,0.314469521304579;3.20731967128992,1.15703487994881;3.44177788297025,-0.496993239232624;2.51022078983829,-1.67441290844976;3.69147624543048,-0.0266369126936839;3.50552341027405,0.678876823160937;1.29388550396712,3.71141751429471;1.73980794220564,-2.81247427172301;2.81335975850807,-1.12971995634260;2.11412475403236,2.84903626317894;3.52006137236472,0.0746347930328961;2.29451845656957,-3.01249827876675;2.25928510933760,2.88707733916192;1.66130362223689,3.62362637793229;0.519628965109547,-3.65486150626913;3.38647428095931,-1.06519588052522;1.18772047293491,-3.42929667216109;0.312821809015028,3.95801048962959;2.63549401816953,-1.67955798595466;2.85772707691467,1.68870021678031;3.35816007074702,0.174892898516875;0.139428513540717,3.71449030848393;2.62737473021890,-2.74267037354551;2.20969610475619,2.37773149906467;2.84315577971697,1.58361751138297;0.495654648775707,-3.94198972095221;0.0386451443921792,-3.97052144740946;1.24796287156667,-2.85421423372850;3.85424961145068,-0.966523212465791;0.210741371962373,3.81106396311375;1.45726025322288,3.30150262421560;3.22206119518507,0.625385084442001;3.31700309569925,1.70892983985444;2.93954237258192,-0.742539116917386;1.69523275652458,-3.34219521970605;2.57136881960244,2.98735595219581;2.71330930116607,2.24954521415671;2.32650287265209,-2.83150904246774;3.52077232410432,-0.585604976410609;2.52357083942858,-2.93321553995649;0.327185032168852,3.28038206246899;0.854474823218118,-2.88689184027279;2.84337375164720,-1.91265530305504;1.73486346520254,-2.72919861786728;3.329553 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论