• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python hierarchy.single函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.cluster.hierarchy.single函数的典型用法代码示例。如果您正苦于以下问题:Python single函数的具体用法?Python single怎么用?Python single使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了single函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: robust_single_linkage

def robust_single_linkage(metric, *, k_neighbors, alpha=None, force_ultrametric=False):
    """Robust single linkage algorithm of (Chaudhuri and Dasgupta 2010).

    Args
    ----
    metric : ndarray
        The distance array to transform, in condensed or square form.
    k_neighbors : int, keyword-only
        The number of neighbors to use in the transformation. Must be 
        a non-negative integer.
    alpha : float, keyword-only, optional
        The connection parameter used in the transformation. At time :math:`r`,
        all edges within :math:`\\alpha r` are connected. Default: 
        :math:`\sqrt{2}`.
    force_ultrametric : bool, keyword-only, optional
        If `True`, the resulting clustering is forced to be ultrametric (each
        point is admitted at radius zero).

    Returns
    -------
    clustering : Clustering
        The robust single linkage clustering.

    """
    kwargs = dict(metric=metric, k_neighbors=k_neighbors, alpha=alpha)
    robust_metric, levels = robust_single_linkage_metric(**kwargs)

    if force_ultrametric:
        levels = None

    # note: _hier.single requires condensed metric!
    linkage = _hier.single(robust_metric)
    return Clustering.from_linkage(linkage, levels=levels)
开发者ID:pombredanne,项目名称:phdlib,代码行数:33,代码来源:clustering.py


示例2: find_closest_two_points

def find_closest_two_points(points):
	
	# use single link clustering to find closest two points
	p = pdist(points)
	slc = single(p)
	
	return np.array([points[slc[0][0]], points[slc[0][1]]])
开发者ID:skavanaugh,项目名称:robot-localization,代码行数:7,代码来源:intersecting_circles.py


示例3: make_tree

def make_tree(X, C, method='single'):
    if method == 'single':
        tree = to_tree(single(C))
    elif method == 'ward':
        tree = to_tree(ward(X))
    elif method == 'average':
        tree = to_tree(average(C))
    return Tree(root=construct_node(tree))
开发者ID:sharadmv,项目名称:trees,代码行数:8,代码来源:agglomerative.py


示例4: group_tuples

def group_tuples(items=None, val_ind=None, dist_thresh = 0.1, distance_matrix=None, 
                 metric='jaccard', linkage='complete', sp_areas=None):
    '''
    items: a dict or list of tuples
    val_ind: the index of the item of interest within each tuple
    '''
    
    if distance_matrix is not None:
        if items is not None:
            if isinstance(items, dict):
                keys = items.keys()
                values = items.values()
            elif isinstance(items, list):
                keys = range(len(items))
                if isinstance(items[0], tuple):
                    values = map(itemgetter(val_ind), items)
                else:
                    values = items
    else:
        if isinstance(items, dict):
            keys = items.keys()
            values = items.values()
        elif isinstance(items, list):
            keys = range(len(items))
            if isinstance(items[0], tuple):
                values = map(itemgetter(val_ind), items)
            else:
                values = items
        else:
            raise Exception('clusters is not the right type')

        assert items is not None, 'items must be provided'
        distance_matrix = compute_pairwise_distances(values, metric, sp_areas=sp_areas)
    
    if items is None:
        assert distance_matrix is not None, 'distance_matrix must be provided.'    
        
    if linkage=='complete':
        lk = complete(squareform(distance_matrix))
    elif linkage=='average':
        lk = average(squareform(distance_matrix))
    elif linkage=='single':
        lk = single(squareform(distance_matrix))

    # T = fcluster(lk, 1.15, criterion='inconsistent')
    T = fcluster(lk, dist_thresh, criterion='distance')
    
    n_groups = len(set(T))
    groups = [None] * n_groups

    for group_id in range(n_groups):
        groups[group_id] = np.where(T == group_id+1)[0]

    index_groups = [[keys[i] for i in g] for g in groups if len(g) > 0]
    item_groups = [[items[i] for i in g] for g in groups if len(g) > 0]
    
    return index_groups, item_groups, distance_matrix
开发者ID:mistycheney,项目名称:MouseBrainAtlas,代码行数:57,代码来源:clustering.py


示例5: cluster_agglomerative

    def cluster_agglomerative(self, n, with_topic):
        #self.n_clusters = n
        if with_topic is True:
            X = self.X_with_topics
        else:
            X = self.X_without_topics

        z = hierarchy.single(pdist(X.toarray(), 'cityblock'))
        self.clusterizer_labels = hierarchy.fcluster(z,n, criterion = 'maxclust')
        cluster_set = set(self.clusterizer_labels)
        self.n_clusters = len(cluster_set) #- (1 if -1 in self.clusterizer_labels else 0)
        if with_topic is True:
            for i in cluster_set: #initialize a dict with cluster no as key to a list
                self.clusters[i] = []
            #adding the actual topics of the cluster to this dict. Mapping of label -> [list of actual topics for the documents clustered in this label]
            for i in range(0,len(self.topic_per_doc)):
                self.clusters[self.clusterizer_labels[i]].append(self.topic_per_doc[i])
            self.generate_piechart_pdf("hierarchical")
        else:
            self.calculate_and_print_silhouette(self.X_without_topics, self.clusterizer_labels, "DBSCAN")
开发者ID:kaushlakers,项目名称:ReuterMinator,代码行数:20,代码来源:clusterer.py


示例6: CalculateClusterTree

	def CalculateClusterTree(self):
		fullMatrix = self.GenerateFullMatrix(self.results)
		dissMatrix = []
		labels = fullMatrix.keys()
		for i in xrange(0, len(labels)):
			sampleNameI = labels[i]
			for j in xrange(i+1, len(labels)):
				sampleNameJ = labels[j]
				dissMatrix.append(fullMatrix[sampleNameI][sampleNameJ])
				
		# calculate hierarchical cluster tree
		if self.radioSingleLinkage.GetValue():
			linkageMatrix = single(dissMatrix)
		elif self.radioUPGMA.GetValue():
			linkageMatrix = average(dissMatrix)
		elif self.radioCompleteLinkage.GetValue():
			linkageMatrix = complete(dissMatrix)
		elif self.radioWeighted.GetValue():
			linkageMatrix = weighted(dissMatrix)
			
		root = to_tree(linkageMatrix)
		
		# create Newick string
		return self.CreateNewickString(root, labels) + ';'
开发者ID:jjhoyt,项目名称:gengis,代码行数:24,代码来源:BetaDiversity.py


示例7: squareform

# <codecell>

np.fill_diagonal(tag_dist_matrix, 0)

# <codecell>

from scipy.spatial.distance import squareform
tag_dist = squareform(tag_dist_matrix)

# <codecell>

from scipy.cluster.hierarchy import single

# <codecell>

tag_linkage = single(tag_dist)

# <codecell>

np.save('tag_linkage',tag_linkage)

# <codecell>

from scipy.cluster.hierarchy import leaves_list, to_tree, dendrogram

# <codecell>

tag_closeness_id = leaves_list(tag_linkage)

# <codecell>
开发者ID:nanumyan,项目名称:iCH-predictor,代码行数:30,代码来源:tag_hierarchical_clustering.py


示例8: check_fcluster_maxclust_monocrit

 def check_fcluster_maxclust_monocrit(self, t):
     expectedT = hierarchy_test_data.fcluster_maxclust[t]
     Z = single(hierarchy_test_data.Q_X)
     T = fcluster(Z, t, criterion='maxclust_monocrit', monocrit=maxdists(Z))
     assert_(is_isomorphic(T, expectedT))
开发者ID:abudulemusa,项目名称:scipy,代码行数:5,代码来源:test_hierarchy.py


示例9: check_fcluster

 def check_fcluster(self, t, criterion):
     # Tests fcluster(Z, criterion=criterion, t=t) on a random 3-cluster data set.
     expectedT = getattr(hierarchy_test_data, 'fcluster_' + criterion)[t]
     Z = single(hierarchy_test_data.Q_X)
     T = fcluster(Z, criterion=criterion, t=t)
     assert_(is_isomorphic(T, expectedT))
开发者ID:abudulemusa,项目名称:scipy,代码行数:6,代码来源:test_hierarchy.py


示例10: print

hclust_model = cluster.AgglomerativeClustering(n_clusters = 2, linkage = 'average')
hclust_model.fit(X)
print('Cluster labels: {}\n'.format(hclust_model.labels_))

hclust_model = cluster.AgglomerativeClustering(n_clusters = 2, linkage = 'complete')
hclust_model.fit(X)
print('Cluster labels: {}\n'.format(hclust_model.labels_))


print '''
*********************************************************************************************************************
                                 scipy: dendrogram
*********************************************************************************************************************
'''

# from: https://github.com/JWarmenhoven/ISLR-python/blob/master/Notebooks/Chapter%2010.ipynb

fig, (ax1,ax2,ax3) = plt.subplots(3,1, figsize=(15,18))

for linkage, cluster, ax in zip([hierarchy.complete(X), hierarchy.average(X), hierarchy.single(X)], ['c1','c2','c3'],
                                [ax1,ax2,ax3]):
    cluster = hierarchy.dendrogram(linkage, ax=ax, color_threshold=0)

ax1.set_title('Complete Linkage')
ax2.set_title('Average Linkage')
ax3.set_title('Single Linkage')

plt.show()

开发者ID:skeydan,项目名称:data-science-with-python,代码行数:28,代码来源:hcluster.py


示例11: PCA

    plt.figure()
    newick = final_tree.to_newick()
    tree = Phylo.read(StringIO(newick), 'newick')

    Phylo.draw_graphviz(tree, prog='neato')
    plt.savefig("%s.png" % name, dpi=200, bbox_inches='tight')
X += np.random.normal(scale=0.01, size=X.shape)

pca = PCA(2)
pca.fit(X)

# X = pca.transform(X)
N, D = X.shape

C = pdist(X)
tree = to_tree(single(C))

def construct_node(snode):
    if snode.left is None and snode.right is None:
        return TreeLeaf(snode.get_id())
    node = TreeNode()
    node.add_child(construct_node(snode.left))
    node.add_child(construct_node(snode.right))
    return node

root = construct_node(tree)
linkage_tree = Tree(root=root)
plot_tree(linkage_tree, 'linkage_induced')


if args.tree:
开发者ID:sharadmv,项目名称:trees,代码行数:31,代码来源:run_linkage.py



注:本文中的scipy.cluster.hierarchy.single函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python hierarchy.to_tree函数代码示例发布时间:2022-05-27
下一篇:
Python hierarchy.num_obs_linkage函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap