IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 《Machine Learning Fundamentals》Class Notes -- Chapter Nine Clustering -> 正文阅读

[人工智能]《Machine Learning Fundamentals》Class Notes -- Chapter Nine Clustering

What are clustering algorithms used for?

We want to divide the data into several different types(different clusters) without labels. Data in the same cluster have some similar features for a given dataset.

We might as well define tihs similarities as distance. Therefore, our goal is to find a partition such that the intra-cluster distance is small and the inter-cluster distance is large.


Figure1:intra-cluster and inter-cluster distance

we need to determine the appropriate distance measure based on the samples. Here we will use Euclidean distance as a similarity measure.

E u c l i d e a n ? d i s t a n c e : ∑ u = 1 n ∥ x i u ? x j u ∥ 2 Euclidean\ distance: \sqrt{\sum_{u=1}^n\|x_{iu}-x_{ju}\|^2} Euclidean?distance:u=1n?xiu??xju?2 ?


Figure2:Clustring

The problem we need to optimize

Divide the dataset { x 1 , x 2 , . . . , x M } \{x_1,x_2,...,x_M\} {x1?,x2?,...,xM?} into disjoint sets { S 1 , S 2 , . . . , S K } \{S_1,S_2,...,S_K\} {S1?,S2?,...,SK?}. For each set S k S_k Sk?, the representative point is chosen as μ k \mu_k μk?.

The loss function can be defined as:
E ( S 1 , . . . , S K ; μ 1 , . . . , μ K ) = 1 N ∑ m = 1 M ∑ k = 1 K [ [ x m ∈ S k ] ] ∥ x m ? μ k ∥ 2 E(S_1,...,S_K;\mu_1,...,\mu_K)=\frac{1}{N}\sum_{m=1}^M\sum_{k=1}^K[[x_m\in S_k]]\|x_m-\mu_k\|^2 E(S1?,...,SK?;μ1?,...,μK?)=N1?m=1M?k=1K?[[xm?Sk?]]xm??μk?2

Therefore, our goal is to find an optimal partition that minimizes E E E.
min ? S 1 , . . . , S K ; μ 1 , . . . , μ K E ( S 1 , . . . , S K ; μ 1 , . . . , μ K ) \min_{S_1,...,S_K;\mu_1,...,\mu_K}E(S_1,...,S_K;\mu_1,...,\mu_K) S1?,...,SK?;μ1?,...,μK?min?E(S1?,...,SK?;μ1?,...,μK?)

(Note: Going directly to find the optimal solution of E E E is an NP-hard problem.)

K-Means

  1. Assuming that μ 1 , . . . , μ k \mu_1,...,\mu_k μ1?,...,μk? have been determined, then for each sample x m x_m xm?, x m x_m xm? can be divided into a certain cluster that minimizes ∑ k = 1 K [ [ x m ∈ S k ] ] ∥ x m ? μ k ∥ 2 \sum_{k=1}^K[[x_m\in S_k]]\|x_m-\mu_k\|^2 k=1K?[[xm?Sk?]]xm??μk?2. (The representative point μ k \mu_k μk? closest to x m x_m xm?).
  2. Assuming that S 1 , . . . , S K S_1,...,S_K S1?,...,SK? have been determined, then for each cluster S k S_k Sk?, we can find a certain representative point μ k \mu_k μk? to minimize E k = ∑ x ∈ S k ∥ x ? μ k ∥ 2 E_k=\sum_{x\in S_k}\|x-\mu_k\|^2 Ek?=xSk??x?μk?2.
    d E k d μ k = ∑ n 1 2 ( x n 1 ? μ k ) ( ? 1 ) + ∑ n 2 2 ( μ k ? x n 2 ) = 2 ( ∣ S k ∣ μ k ? ∑ x ∈ S k x ) \frac{d E_k}{d \mu_k}=\sum_{n_1}2(x_{n_1}-\mu_k)(-1)+\sum_{n_2}2(\mu_k-x_{n_2})=2(|S_k| \mu_k-\sum_{x\in S_k}x) dμk?dEk??=n1??2(xn1???μk?)(?1)+n2??2(μk??xn2??)=2(Sk?μk??xSk??x)
    So, when μ k = 1 ∣ S k ∣ ∑ x ∈ S k x \mu_k=\frac{1}{|S_k|}\sum_{x\in S_k}x μk?=Sk?1?xSk??x, the derivative of E k E_k Ek? with respect to μ k \mu_k μk? is 0. (The μ k \mu_k μk? also called the means vector for cluster S k S_k Sk?)
  3. Steps 1 and 2 are repeated until the representative points μ \mu μ no longer change.

When we do the above operations, the value of E E E is updated to E ′ E' E, E ′ ≤ E E'\le E EE, and E E E has a lower bound E ≥ 0 E\ge 0 E0.
Therefore, it has been proved that the loss function must converge.
(Note: the loss function will eventually converge to a local extremum, not necessarily a global minimum.)

This also can be proved by EM(Expectation-Maximization) algorithm.

X-means

In the K-means algorithm, the value of K K K is fixed. However, it is often difficult to choose the best K K K.

For the X-means algorithm, users can choose a range of K K K, and the X-means first runs the ordinary K-means algorithm according to the lower limit of the range. According to the value of BIC(Bayesian information criterion), the X-means algorithm determines whether to divide each cluster into two.
PDF: X-means: Extending K-means with Efficient Estimation of the Number of Clusters


Figure3: An illustration of X-means algorithm. Source: www.cs.cmu.edu

Hierarchical Clustering

Hierarchical clustering provides another idea to help users interpret the appropriate number of clusters.

Take AGNES(AGglomerative NESting) as an example:

  1. Consider each sample as a cluster.
  2. Merge the two clusters with the smallest distance. (inter-cluster distance)
  3. Steps 1 and 2 are repeated until all clusters are merged into one single cluster including all points.

Figure4: An illustration of hierarchical clustering. Source: 🍉 Book

Users can observe the distance between clusters and choose an optimal K K K by themselves.

Code(K-means)

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from sklearn.cluster import KMeans

data = np.random.randint(0,50,size=[100,2])
K = 4 # fix the value of K
kmeans = KMeans(n_clusters=K, random_state=0).fit(data)
subCenter = list(kmeans.labels_)

# drawing
samples = [[] for i in range(K)]
for i in range(np.shape(data)[0]):
    tmp = [data[i][0], data[i][1]]
    samples[subCenter[i]].append(tmp)
plt.plot(np.array(samples[0])[:, :1], np.array(samples[0])[:, 1:], 'b.')
plt.plot(np.array(samples[1])[:, :1], np.array(samples[1])[:, 1:], 'r.')
plt.plot(np.array(samples[2])[:, :1], np.array(samples[2])[:, 1:], 'y.')
plt.plot(np.array(samples[3])[:, :1], np.array(samples[3])[:, 1:], 'g.')
plt.show()

Figure5: The result of K-means
  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-05-09 12:39:40  更:2022-05-09 12:45:18 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 7:39:14-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码