当前位置: 首页>>代码示例>>Python>>正文


Python Pycluster.somcluster方法代码示例

本文整理汇总了Python中Pycluster.somcluster方法的典型用法代码示例。如果您正苦于以下问题:Python Pycluster.somcluster方法的具体用法?Python Pycluster.somcluster怎么用?Python Pycluster.somcluster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pycluster的用法示例。


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

示例1: som_cluster_test

# 需要导入模块: import Pycluster [as 别名]
# 或者: from Pycluster import somcluster [as 别名]
def som_cluster_test(data,real_labels, outputfile = None):
    if outputfile != None:
        f = open(outputfile,'w')
        f.write(out_result_header())

    start = time.time()
    ks = range(6,40)
    for k in ks:
        print 'som clustering when k=%d' % k
        predicted = Pycluster.somcluster(data,nxgrid=k,nygrid=1, niter=5, dist='u')[0]
        predicted = [xy[0] for xy in predicted.tolist()]
        cata = tuple(set(predicted))
        for i in range(0,len(predicted)):
            predicted[i]=cata.index(predicted[i])
        if outputfile != None:
            f.write(out_result(predicted, k, real_labels))

    elasped = time.time() - start
    print 'som clustering time: %.3f' % (elasped/float(len(ks)))
开发者ID:Calvin-he,项目名称:docclustering,代码行数:21,代码来源:kmeans.py

示例2: self_organizing_map

# 需要导入模块: import Pycluster [as 别名]
# 或者: from Pycluster import somcluster [as 别名]
def self_organizing_map(flat_data, data):
    """ """
    # Self-organizing maps
    clusterid, celldata = pc.somcluster(
                        data=flat_data.values(),
                        transpose=0,
                        nxgrid=5,
                        nygrid=5,
                        inittau=0.02,
                        niter=100,
                        dist='e')
                        
    # load clusters into dictionary
    clusters = defaultdict(list)
    for i, j in zip(clusterid, data):
        clusters[tuple(i)].append(j)
    
    make_plots('SOM (c=%s, m=%s, d=%s)' % (nclusters, method, distance),
                   clusters, flat_data)
开发者ID:audy,项目名称:clump,代码行数:21,代码来源:clustering.py

示例3:

# 需要导入模块: import Pycluster [as 别名]
# 或者: from Pycluster import somcluster [as 别名]
		input_vecs = utils.make_prices_diffs_vecs(data)
	else:
		input_vecs = utils.make_prices_vecs(data)

	# Run clustering algorithm.

	if algorithm_type == ClusterAlg.KMEANS:
		labels, wcss, n = Pycluster.kcluster(input_vecs, number_of_clusters, 
				dist = dist_measure, npass = number_of_iters, 
				method = dist_method)
	elif algorithm_type == ClusterAlg.HIERARCHICAL:
		tree = Pycluster.treecluster(input_vecs, method = dist_method,
				dist = dist_method)
		labels = tree.cut(number_of_clusters)
	elif algorithm_type == ClusterAlg.SELFORGMAPS:
		labels, celldata = Pycluster.somcluster(input_vecs, nxgrid = xgrid, 
				nygrid = ygrid, niter = number_of_iters)

	# If algorithm is self-organizing maps each item is assigned to
	# a particular 2D point, so we need to create groups from 2D points.
	# See implementation of making groups from labels for details.

	if algorithm_type == ClusterAlg.SELFORGMAPS:
		clusters = utils.make_groups_from_labels(labels, data, True)
	else:
		clusters = utils.make_groups_from_labels(labels, data)

	# Check with which type of key we have to deal with.
	# Any better idea how to check if object is a pair? :)

	keys_are_2D_points = True
	sample_key = clusters.keys()[0]
开发者ID:kstosiek,项目名称:HDiDM2010,代码行数:34,代码来源:cluster.py


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