数据挖掘与分析课程笔记(Chapter 15)

数据挖掘与分析课程笔记

  • 参考教材:Data Mining and Analysis : MOHAMMED J.ZAKI, WAGNER MEIRA JR.

文章目录

  1. 数据挖掘与分析课程笔记(目录)
  2. 数据挖掘与分析课程笔记(Chapter 1)
  3. 数据挖掘与分析课程笔记(Chapter 2)
  4. 数据挖掘与分析课程笔记(Chapter 5)
  5. 数据挖掘与分析课程笔记(Chapter 7)
  6. 数据挖掘与分析课程笔记(Chapter 14)
  7. 数据挖掘与分析课程笔记(Chapter 15)
  8. 数据挖掘与分析课程笔记(Chapter 20)
  9. 数据挖掘与分析课程笔记(Chapter 21)


Chapter 15:基于密度的聚类

适用数据类型:非凸,又称非凸聚类;K-means 适用于凸数据

15.1 DBSCAN 算法

  • 定义记号: ∀ x ∈ R d , N ϵ ( x ) : = { y ∈ R d ∣ δ ( x − y ) ≤ ϵ } \forall \mathbf{x}\in \mathbb{R}^d,N_{\epsilon}(\mathbf{x}):=\{\mathbf{y}\in \mathbb{R}^d|\delta(\mathbf{x}-\mathbf{y})\le\epsilon \} xRd,Nϵ(x):={yRdδ(xy)ϵ},其中 δ ( x − y ) = ∣ ∣ x − y ∣ ∣ \delta(\mathbf{x}-\mathbf{y})=||\mathbf{x}-\mathbf{y}|| δ(xy)=∣∣xy∣∣ 欧式距离,其他距离也可。 D ⊆ R d \mathbf{D}\subseteq \mathbb{R}^d DRd

Def.1 m i n p t s ∈ N + minpts \in \mathbb{N}_+ minptsN+ 是用户定义的局部密度,如果 ∣ N ϵ ( x ) ∩ D ∣ ≥ m i n p t s |N_{\epsilon}(\mathbf{x})\cap\mathbf{D}|\ge minpts Nϵ(x)Dminpts ,则称 x \mathbf{x} x D \mathbf{D} D 核心点;如果 ∣ N ϵ ( x ) ∩ D ∣ < m i n p t s |N_{\epsilon}(\mathbf{x})\cap\mathbf{D}|< minpts Nϵ(x)D<minpts ,且 x ∈ N ϵ ( z ) \mathbf{x}\in N_{\epsilon}(\mathbf{z}) xNϵ(z) ,其中 z \mathbf{z} z D \mathbf{D} D 的核心点,则称 x \mathbf{x} x D \mathbf{D} D 的边缘点;如果 x \mathbf{x} x 既不是核心点又不是边缘点,则称 x \mathbf{x} x D \mathbf{D} D 的噪点。

Def.2 如果 x ∈ N ϵ ( y ) \mathbf{x}\in N_{\epsilon}(\mathbf{y}) xNϵ(y) y \mathbf{y} y 是核心点,则称 x \mathbf{x} x y \mathbf{y} y 是直接密度可达的。如果存在点列 x 0 , x 1 , ⋯   , x l \mathbf{x}_0,\mathbf{x}_1,\cdots,\mathbf{x}_l x0,x1,,xl,使得 x 0 = x , x l = y \mathbf{x}_0=\mathbf{x},\mathbf{x}_l=\mathbf{y} x0=x,xl=y,且 x i \mathbf{x}_{i} xi x i − 1 \mathbf{x}_{i-1} xi1 是直接密度可达,则称 x \mathbf{x} x y \mathbf{y} y 是密度可达。

Def.3 如果存在 z ∈ D \mathbf{z}\in \mathbf{D} zD,使得 x \mathbf{x} x y \mathbf{y} y z \mathbf{z} z 都是密度可达的,称 x \mathbf{x} x y \mathbf{y} y 是密度连通的。

Def.4 基于密度的聚类是指基数最大的密度连通集(即集合内任意两点都是密度连通)。

算法15.1 : DBSCAN ( O ( n 2 ) O(n^2) O(n2))

输入: D , ϵ , m i n p t s \mathbf{D}, \epsilon, minpts D,ϵ,minpts

输出: C , C o r e , B o r d e r , N o i s e \mathcal{C},Core,Border,Noise C,Core,Border,Noise

  1. C o r e ← ∅ Core \leftarrow \emptyset Core

  2. 对每一个 x i ∈ D \mathbf{x}_i\in \mathbf{D} xiD

    2.1 计算 N ϵ ( x i ) ( ⊆ D ) N_\epsilon(\mathbf{x}_i)(\subseteq \mathbf{D}) Nϵ(xi)(D)

    2.2 i d ( x i ) ← ∅ id(\mathbf{x}_i)\leftarrow \emptyset id(xi)

    2.3 如果 N ϵ ( x i ) ≥ m i n p t s N_\epsilon(\mathbf{x}_i)\ge minpts Nϵ(xi)minpts,则 C o r e ← C o r e ∪ { x i } Core\leftarrow Core \cup \{ \mathbf{x}_i\} CoreCore{xi}

  3. k ← 0 k\leftarrow 0 k0

  4. 对每一个 x i ∈ C o r e , s . t . i d ( x i ) = ∅ \mathbf{x}_i\in Core, s.t.id(\mathbf{x}_i)= \emptyset xiCore,s.t.id(xi)=,执行

    4.1 k ← k + 1 k\leftarrow k+1 kk+1

    4.2 i d ( x i ) ← k id(\mathbf{x}_i)\leftarrow k id(xi)k

    4.3 D e n s i t y C o n n e c t e d ( x i , k ) Density Connected (\mathbf{x}_i,k) DensityConnected(xi,k)

  5. C ← { C i } i = 1 k \mathcal{C}\leftarrow \{ C_i\}_{i=1}^k C{Ci}i=1k,其中 C i ← { x i ∈ D ∣ i d ( x i ) = i } C_i\leftarrow \{\mathbf{x}_i \in \mathbf{D} |id(\mathbf{x}_i)=i\} Ci{xiDid(xi)=i}

  6. N o i s e ← { x i ∈ D ∣ i d ( x i ) = ∅ } Noise \leftarrow \{\mathbf{x}_i \in \mathbf{D} |id(\mathbf{x}_i)=\emptyset\} Noise{xiDid(xi)=}

  7. B o r d e r ← D ∖ { C o r e ∪ N o i s e } Border\leftarrow \mathbf{D}\setminus \{Core\cup Noise \} BorderD{CoreNoise}

  8. return C , C o r e , B o r d e r , N o i s e \mathcal{C},Core,Border,Noise C,Core,Border,Noise

D e n s i t y C o n n e c t e d ( x i , k ) Density Connected (\mathbf{x}_i,k) DensityConnected(xi,k)

  1. 对于每一个 y ∈ N ϵ ( x ) ∖ x \mathbf{y} \in N_\epsilon(\mathbf{x}) \setminus {\mathbf{x}} yNϵ(x)x

    1.1 i d ( y ) ← k id(\mathbf{y})\leftarrow k id(y)k

    1.2 如果 y ∈ C o r e \mathbf{y}\in Core yCore,则 D e n s i t y C o n n e c t e d ( y , k ) Density Connected (\mathbf{y},k) DensityConnected(y,k)

Remark:DBSCAN 对 ε \varepsilon ε 敏感: ε \varepsilon ε 过小,稀疏的类可能被认作噪点; ε \varepsilon ε 过大,稠密的类可能无法区分。

15.2 密度估计函数(DEF)

∀ z ∈ R d \forall \mathbf{z}\in \mathbb{R}^d zRd,定义 K ( z ) = 1 ( 2 π ) d / 2 e − z T z 2 K(\mathbf{z})=\frac{1}{(2\pi)^{d/2}}e^{-\frac{\mathbf{z}^T\mathbf{z}}{2}} K(z)=(2π)d/21e2zTz ∀ x ∈ R d , f ^ ( x ) : = 1 n h d ∑ i = 1 n K ( x − x i h ) \forall \mathbf{x}\in \mathbb{R}^d,\hat{f}(\mathbf{x}):=\frac{1}{nh^d}\sum\limits_{i=1}^{n}K(\frac{\mathbf{x}-\mathbf{x}_i}{h}) xRd,f^(x):=nhd1i=1nK(hxxi)

其中 h > 0 h>0 h>0 是用户指定的步长, { x 1 , ⋯   , x n } \{\mathbf{x}_1,\cdots,\mathbf{x}_n\} {x1,,xn} 是给定的数据集

15.3 DENCLUE

Def.1 x ∗ ∈ R d \mathbf{x}^*\in \mathbb{R}^d xRd 是密度吸引子,如果它决定概率密度函数 f f f 的一个局部最大值。(PDF一般未知)

x ∗ ∈ R d \mathbf{x}^*\in \mathbb{R}^d xRd x ∈ R d \mathbf{x}\in \mathbb{R}^d xRd 的密度吸引子,如果存在 x 0 , x 1 , … , x m \mathbf{x}_0,\mathbf{x}_1,\dots,\mathbf{x}_m x0,x1,,xm,使得 x 0 = x , ∣ ∣ x m − x ∗ ∣ ∣ ≤ ϵ \mathbf{x}_0=\mathbf{x},||\mathbf{x}_m-\mathbf{x}^*||\le\epsilon x0=x,∣∣xmx∣∣ϵ,且 x t + 1 = x t + δ ⋅ ∇ f ^ ( x t ) ( 1 ) \mathbf{x}_{t+1}=\mathbf{x}_{t}+\delta \cdot \nabla \hat{f}(\mathbf{x}_{t})\quad (1) xt+1=xt+δf^(xt)(1)

其中 ϵ , δ > 0 \epsilon,\delta >0 ϵ,δ>0 是用户定义的误差及步长, f ^ \hat{f} f^ 是DEF。

  • 更高效的迭代公式:

动机:当 x \mathbf{x} x 靠近 x ∗ \mathbf{x}^* x 时,迭代公式(1)迭代效率低 ∇ f ^ ( x ∗ ) = 0 \nabla \hat{f}(\mathbf{x}^*)=0 f^(x)=0

∇ f ^ ( x ) = ∂ ∂ x f ^ ( x ) = 1 n h d ∑ i = 1 n ∂ ∂ x K ( x − x i h ) \nabla \hat{f}(\mathbf{x})=\frac{\partial}{\partial \mathbf{x}} \hat{f}(\mathbf{x})=\frac{1}{n h^{d}} \sum\limits_{i=1}^{n} \frac{\partial}{\partial \mathbf{x}} K\left(\frac{\mathbf{x}-\mathbf{x}_{i}}{h}\right) f^(x)=xf^(x)=nhd1i=1nxK(hxxi)

∂ ∂ x K ( z ) = ( 1 ( 2 π ) d / 2 exp ⁡ { − z T z 2 } ) ⋅ − z ⋅ ∂ z ∂ x = K ( z ) ⋅ − z ⋅ ∂ z ∂ x \begin{aligned} \frac{\partial}{\partial \mathbf{x}} K(\mathbf{z}) &=\left(\frac{1}{(2 \pi)^{d / 2}} \exp \left\{-\frac{\mathbf{z}^{T} \mathbf{z}}{2}\right\}\right) \cdot-\mathbf{z} \cdot \frac{\partial \mathbf{z}}{\partial \mathbf{x}} \\ &=K(\mathbf{z}) \cdot-\mathbf{z} \cdot \frac{\partial \mathbf{z}}{\partial \mathbf{x}} \end{aligned} xK(z)=((2π)d/21exp{2zTz})zxz=K(z)zxz

z = x − x i h \mathbf{z}=\frac{\mathbf{x}-\mathbf{x}_i}{h} z=hxxi 代入得: ∂ ∂ x K ( x − x i h ) = K ( x − x i h ) ⋅ ( x i − x h ) ⋅ ( 1 h ) \frac{\partial}{\partial \mathbf{x}} K\left(\frac{\mathbf{x}-\mathbf{x}_{i}}{h}\right)=K\left(\frac{\mathbf{x}-\mathbf{x}_{i}}{h}\right) \cdot\left(\frac{\mathbf{x}_{i}-\mathbf{x}}{h}\right) \cdot\left(\frac{1}{h}\right) xK(hxxi)=K(hxxi)(hxix)(h1)

故有: ∇ f ^ ( x ) = 1 n h d + 2 ∑ i = 1 n K ( x − x i h ) ⋅ ( x i − x ) \nabla \hat{f}(\mathbf{x})=\frac{1}{n h^{d+2}} \sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}-\mathbf{x}_{i}}{h}\right) \cdot\left(\mathbf{x}_{i}-\mathbf{x}\right) f^(x)=nhd+21i=1nK(hxxi)(xix)

则: 1 n h d + 2 ∑ i = 1 n K ( x ∗ − x i h ) ⋅ ( x i − x ∗ ) = 0 \frac{1}{n h^{d+2}} \sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}^*-\mathbf{x}_{i}}{h}\right) \cdot\left(\mathbf{x}_{i}-\mathbf{x}^*\right)=0 nhd+21i=1nK(hxxi)(xix)=0

故有: x ∗ = ∑ i = 1 n K ( x ∗ − x i h ) ⋅ x i ∑ i = 1 n K ( x ∗ − x i h ) ( 2 ) \mathbf{x}^*=\frac{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}^*-\mathbf{x}_{i}}{h}\right)\cdot \mathbf{x}_{i}}{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}^*-\mathbf{x}_{i}}{h}\right)}\quad (2) x=i=1nK(hxxi)i=1nK(hxxi)xi(2)

由(1): x t + 1 − x t = δ ⋅ ∇ f ^ ( x t ) \mathbf{x}_{t+1}-\mathbf{x}_{t}=\delta \cdot \nabla \hat{f}(\mathbf{x}_{t}) xt+1xt=δf^(xt),(靠近 x ∗ \mathbf{x}^* x 时)近似有: x t + 1 − x t ≈ 0 \mathbf{x}_{t+1}-\mathbf{x}_{t}\approx0 xt+1xt0

且: x t = ∑ i = 1 n K ( x t − x i h ) ⋅ x i ∑ i = 1 n K ( x t − x i h ) \mathbf{x}_t=\frac{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}_t-\mathbf{x}_{i}}{h}\right)\cdot \mathbf{x}_{i}}{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}_t-\mathbf{x}_{i}}{h}\right)} xt=i=1nK(hxtxi)i=1nK(hxtxi)xi

故: x t + 1 = ∑ i = 1 n K ( x t − x i h ) ⋅ x i ∑ i = 1 n K ( x t − x i h ) \mathbf{x}_{t+1}=\frac{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}_t-\mathbf{x}_{i}}{h}\right)\cdot \mathbf{x}_{i}}{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}_t-\mathbf{x}_{i}}{h}\right)} xt+1=i=1nK(hxtxi)i=1nK(hxtxi)xi

Def.2 C ⊆ D C\subseteq \mathbf{D} CD 是基于密度的类,如果存在密度吸引子 x 1 ∗ , … , x m ∗ \mathbf{x}^*_1,\dots,\mathbf{x}^*_m x1,,xm s . t : s.t: s.t:

  1. ∀ x ∈ C \forall \mathbf{x}\in C xC 都有某个 x i ∗ \mathbf{x}^*_i xi 使得, x i ∗ \mathbf{x}^*_i xi x \mathbf{x} x 的密度吸引子;
  2. ∀ i , f ^ ( x i ∗ ) ≥ ξ \forall i,\hat{f}(\mathbf{x}^*_i)\ge \xi i,f^(xi)ξ,其中 ξ \xi ξ 是用户指定的极小密度阈值;
  3. ∀ x i ∗ , x j ∗ \forall\mathbf{x}^*_i,\mathbf{x}^*_j xi,xj 都密度可达,即存在路径从 x i ∗ \mathbf{x}^*_i xi x j ∗ \mathbf{x}^*_j xj 使得路径上所有点 y \mathbf{y} y 都有 f ^ ( y ) ≥ ξ \hat{f}(\mathbf{y})\ge\xi f^(y)ξ

算法15.2 : DENCLUE 算法

输入: D , h , ξ , ϵ \mathbf{D},h,\xi,\epsilon D,h,ξ,ϵ

输出: C \mathcal{C} C (基于密度的聚类)

  1. A ← ∅ \mathcal{A}\leftarrow\emptyset A

  2. 对每一个 x ∈ D \mathbf{x}\in \mathbf{D} xD:

    2.1 x ∗ ← F I N D A T T R A C T O R ( x , D , h , ξ , ϵ ) \mathbf{x}^* \leftarrow FINDATTRACTOR(\mathbf{x},\mathbf{D},h,\xi,\epsilon) xFINDATTRACTOR(x,D,h,ξ,ϵ)

    2.2 R ( x ∗ ) ← ∅ R(\mathbf{x}^*)\leftarrow\emptyset R(x)

    2.3 if f ^ ( x ∗ ) ≥ ξ \hat{f}(\mathbf{x}^*)\ge \xi f^(x)ξ then:

    2.4 A ← A ∪ { x ∗ } \mathcal{A}\leftarrow \mathcal{A}\cup\{ \mathbf{x}^*\} AA{x}

    2.5 R ( x ∗ ) ← R ( x ∗ ) ∪ { x ∗ } R(\mathbf{x}^*)\leftarrow R(\mathbf{x}^*)\cup\{ \mathbf{x}^* \} R(x)R(x){x}

  3. C ← { maximal  C ⊆ A ∣ ∀ x i ∗ , x j ∗ ∈ C , 满足 D e f   2 条件 3 } \mathcal{C}\leftarrow\{\text{maximal}\ C \subseteq \mathcal{A}| \forall\mathbf{x}^*_i,\mathbf{x}^*_j \in C, 满足 Def \ 2 条件3 \} C{maximal CA∣∀xi,xjC,满足Def 2条件3}

  4. ∀ C ∈ C : \forall C \in \mathcal{C}: CC:

    4.1 对每一个 x ∗ ∈ C \mathbf{x}^*\in C xC,令 C ← C ∪ R ( x ∗ ) C\leftarrow C\cup R(\mathbf{x}^*) CCR(x)

  5. Return C \mathcal{C} C

F I N D A T T R A C T O R ( x , D , h , ξ , ϵ ) FINDATTRACTOR(\mathbf{x},\mathbf{D},h,\xi,\epsilon) FINDATTRACTOR(x,D,h,ξ,ϵ):

  1. t ← 0 t\leftarrow 0 t0

  2. x t = x \mathbf{x}_{t}=\mathbf{x} xt=x

  3. Repeat:

    x t + 1 ← ∑ i = 1 n K ( x t − x i h ) ⋅ x i ∑ i = 1 n K ( x t − x i h ) \mathbf{x}_{t+1}\leftarrow\frac{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}_t-\mathbf{x}_{i}}{h}\right)\cdot \mathbf{x}_{i}}{\sum\limits_{i=1}^{n} K\left(\frac{\mathbf{x}_t-\mathbf{x}_{i}}{h}\right)} xt+1i=1nK(hxtxi)i=1nK(hxtxi)xi

    t ← t + 1 t\leftarrow t+1 tt+1

  4. Until ∣ ∣ x t − x t − 1 ∣ ∣ < ϵ ||\mathbf{x}_{t}-\mathbf{x}_{t-1}||<\epsilon ∣∣xtxt1∣∣<ϵ


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值