机器学习入门|聚类(二)

156 阅读3分钟
原文链接: click.aliyun.com

密度聚类

顾名思义,密度聚类是基于样本分布的紧密程度来划分的。因为这个性质,密度聚类可以划分出形状不规则的簇,弥补了原型聚类只能划分凸形的聚类簇的不足。

DBSCAN算法

DBSCAN算法是基于邻域参数 ( ϵ , M i n P t s ) " role="presentation ">(\epsilon,MinPts) 来刻画样本分布的紧密程度。

几个概念:

  • ϵ " role="presentation ">\epsilon 邻域:给定对象半径 ϵ " role="presentation ">\epsilon 内的区域
  • 核心对象:对象的 ϵ " role="presentation ">\epsilon 邻域内有至少MinPts个样本点,则该对象为核心对象
  • 密度值达:对于样本集合D,样本点 x j " role="presentation ">x_{j} 在 x i " role="presentation ">x_{i} 的 ϵ " role="presentation ">\epsilon 邻域内,且 x i " role="presentation ">x_{i} 为核心对象,则称 x j " role="presentation ">x_{j} 由 x i " role="presentation ">x_{i} 密度直达
  • 密度可达:若 x i " role="presentation ">x_{i} 由 x i − 1 ( i = 2 , 3 , . . . n ) " role="presentation ">x_{i-1} (i=2,3,...n)
                                                            密度直达,则称 x 1 " role="presentation ">x_{1} 由 x n " role="presentation ">x_{n} 密度可达
  • 密度相连:若 x i " role="presentation ">x_{i} 和 x j " role="presentation ">x_{j} 均由 x k " role="presentation ">x_{k} 密度可达,则 x i " role="presentation ">x_{i} 和 x j " role="presentation ">x_{j} 密度相连

如果把一个核心对象以及由这个核心对象导出的所有密度可达的样本点组成一个集合,则此集合就是一个聚类簇,即DBSCAN算法就是通过遍历每一个未被划分的样本点来进行簇划分,而不是核心对象且没有归属的簇的样本点就是噪声点。

DBSCAN算法的邻域 ϵ " role="presentation ">\epsilon 和MinPts都需要使用者指定。它的缺陷是很难识别密度不同的簇,MinPts过高,则有可能使部分低密度的数据诶被错误地当成噪声点,MinPts过低,则无法正确划分高密度的簇,使不同的簇被划分到一起。

层次聚类

层次聚类对数据集进行拆分或者合并操作最终形成簇划分的一种聚类思路

AGNES算法

AGNES算法采用合并策略进行聚类,初始使数据集中每一个样本都已是一个簇,之后通过找出最近的两个簇进行合并,递归进行直到满足停止条件或者所有书籍都合并成一个簇。这里判断最近距离可以采用不同的距离计算。

1.最小距离: d m i n ( C i , C j ) = m i n ( d i s t ( x , z ) ) " role="presentation ">d_{min}(C_{i},C_{j})=min(dist(x,z))
                                                            即两个簇之间距离最近的两个样本的距离
2.最大距离: d m a x ( C i , C j ) = m a x ( d i s t ( x , z ) ) " role="presentation ">d_{max}(C_{i},C_{j})=max(dist(x,z))
                                                            即两个簇之间距离最大的样本之间的距离
3.平均距离: d a v g ( C i , C j ) = 1 | C i | | C j | ∑ x ∈ C i ∑ x ∈ C j d i s t ( x , z ) " role="presentation ">d_{avg}(C_{i},C_{j})=\frac{1}{|C_{i}||C_{j}|}\sum_{x\in C_{i}}\sum_{x\in C_{j}} dist(x,z) 即质心距离

其中, C i ( i = 1 , 2 , . . . , n ) " role="presentation ">C_{i} (i=1,2,...,n)
                                                            是簇, x , z " role="presentation ">x,z 分别是 C i , C j " role="presentation ">C_{i},C_{j} 中的样本点

默认情况下, d i s t ( ) " role="presentation ">dist() 为欧氏距离。

由于算法复杂度为 O ( n 2 ) " role="presentation ">O(n^{2}) ,不适合大数据集。

层次聚类过程最明显的特点就是不可逆性,由于对象在合并或分裂之后,下一次聚类会在前一次聚类基础之上继续进行合并或分裂,结果一旦产生就无法变更。

由于聚类是无监督学习,不同的聚类算法还有很多,且都有各自的作用,例如把数据量化成有限单元,使所有的聚类操作都在这个网格结构(即量化的空间)上进行的网格聚类;对每一个簇都假设一个模型进行拟合的模型聚类等。