# AGNES层次聚类

试图从不同层次对数据集进行划分，从而形成树形的聚类结构。自底向上的聚会策略，先将每个样本看做一个聚类簇（m个样本就是m个簇），然后每次运行找出距离最近的两个簇进行合并，不断重复，直到达到设定的k值。注意的是，簇的距离计算的定义：

按照这3种min、max、avg计算距离，AGNES算法被称为“单链接”、“全链接”、“均链接”

算法流程（《机器学习》周志华，p215）：

> 6,7行计算每个样本间相互距离；13-15合并 i *和 j* 两号的簇并入 i *内，j* 以后的簇全部更新编号;
>
> 17行，删除所有与 j\* 号簇有关的距离信息;
>
> 19-20行，（只需要）更新第 i\* 号簇与其他簇的距离;

![img](https://img-blog.csdnimg.cn/20190302115216972.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nNDI1Nzc2MDI0,size_16,color_FFFFFF,t_70)

图例：

![img](https://img-blog.csdnimg.cn/20190302120316129.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nNDI1Nzc2MDI0,size_16,color_FFFFFF,t_70)

sklearn中没有实现DBSCAN层次聚类的算法，不过这个算法实际操作简单，而且下面有一个更实用的层次聚类算法在sklearn中有实现，因此这个可以看看作为思想


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/ml/cluster/agnes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
