博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解析hierarchical.py from sklearn
阅读量:6715 次
发布时间:2019-06-25

本文共 1543 字,大约阅读时间需要 5 分钟。

解析hierarchical.py内部函数

From Agglomerative clustering,

self.children_, self.n_components_, self.n_leaves_, parents = \        memory.cache(tree_builder)(X, connectivity,                                   n_clusters=n_clusters, **kwargs)

memory.cache input X,connectivity to tree_builder (line 739), tree_builder is initialized by self.linkage (line 712)

tree_builder = _TREE_BUILDERS[self.linkage]

Here, linkage='ward' by default, go back to ward_tree (line 86)

The connectivity parameter is a $n\times n$ can restrict the clustering, those have no connectivity can not be clustered together

connectivity, n_components = _fix_connectivity(X, connectivity, affinity='euclidean')# generalized connectivity, prevent it from empty, all are True by default

then, create nodes:

if n_clusters is None:    n_nodes = 2 * n_samples - 1# binary tree has 2*n-1 nodes totallyelse:    n_nodes = 2 * n_samples - n_clusters# stop when there are enough clusters, if never stop then it will go to 1 cluster finally

build a heap for inertia, then pop one by one to build the cluster tree

heapify(inertia)

in the loop (begin from line 239)

for k in range(n_samples, n_nodes):    # identify the merge    while True:        inert, i, j = heappop(inertia)        if used_node[i] and used_node[j]:            break    parent[i], parent[j] = k, k    children.append((i, j))    # merge i and j, stored in children

after merge, put the new node in the heap (line 274)

[heappush(inertia, (ini[idx], k, coord_col[idx])) for idx in range(n_additions)]

then one iteration ends

转载地址:http://clelo.baihongyu.com/

你可能感兴趣的文章
bgp发布路由对端无法收到,原因是使用默认网段
查看>>
JQuery实现简单的服务器轮询效果
查看>>
幽灵漏洞(GHOST)影响大量Linux操作系统及其发行版(更新修复方案)
查看>>
Sunday算法
查看>>
netstat
查看>>
优朋普乐:OTT正重构电视版图
查看>>
遇到"process launch failed: Security"问题,解决的一种方法
查看>>
Ubuntu 14.04 LTC 有线网络——网线不识别,灯不亮问题
查看>>
Unity3D DLL加密
查看>>
求数组中最长递增子序列
查看>>
Spring Boot cache backed redis
查看>>
有趣的编程----控制自己电脑的CPU
查看>>
linux的目录结构
查看>>
Java中创建对象的5种不同方法
查看>>
Supervisor安装
查看>>
自建框架知识点一命名空间和自动加载
查看>>
21_css布局2_浮动布局.html
查看>>
DateUtils 单元下的公用函数目录
查看>>
构建高效安全的Nginx Web服务器
查看>>
jQuery 练习[二]: 获取对象(1) - 基本选择与层级
查看>>