本文整理汇总了Python中cluster.Cluster.set_label方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.set_label方法的具体用法?Python Cluster.set_label怎么用?Python Cluster.set_label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.set_label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reclusterWithOPTICS
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import set_label [as 别名]
def reclusterWithOPTICS(clustering, resolution=5, display=9):
print "Aproximating Distances"
distances = pseudoDistance(clustering)
print "Running OPTICS"
newClusters = []
clusters = []
centers = map(lambda x: x.center, clustering)
for i,d in enumerate(distances):
#d = distances[0]
subclusters = []
assert(d[0][0] == 0)
label = clustering[i].label
#map from reachability point to document
revIdx = lambda x: clustering[i].members[x._id-1] if (x._id >0) else clustering[i].center
print
print
print "Cluster:", i
#Output is a list of reachability points
output = OPTICS(d,resolution, clustering[i])
displayTruePlot(output, clustering[i], resolution, display)
#Clustering of reachability points
outputClusters = separateClusters(output, resolution)
#remove the cluster center
del outputClusters[0][0]
#subclustering of documents
subclusters = map(lambda c:map(revIdx, c) , outputClusters)
'''
if (len(subclusters) == 1):
cl = clustering[i]
cl.set_label()
clusters.append(cl)
continue
'''
#The largest minima
minimum = selectMinimum(output,resolution)[:display-1]
reps = map(revIdx, minimum)
'''
same, different = simulateUserFeedback(label, reps)
print "Minima:", map(lambda x: (x.reachability, output.index(x)),minimum)
print "Same:", len(same)
print "Different:", len(different)
#displayPoints([centers[i]] + reps)
mergedClusters = []
for rep in same:
for cl in subclusters:
if rep in cl:
mergedClusters += cl
subclusters.remove(cl)
'''
'''
if (len(mergedClusters) > 0):
subclusters = [mergedClusters] + subclusters
'''
subclusters = filter(lambda x: len(x) > 0, subclusters)
for c, cl in enumerate(subclusters):
center = cl[0]
map(lambda x: center.aggregate(x), cl[1:])
newCluster = Cluster(members=cl, center=center)
newCluster.set_label()
newClusters.append(newCluster)
'''
if(len(mergedClusters) > 0):
cl = Cluster(members=mergedClusters, center=clustering[i].center)
cl.set_label()
clusters.append(cl)
'''
'''
purity = validate([clustering[i]])
print "Original Purity", purity
print
purities = validate(newClusters, display=True)
print "Average Purity:", sum(purities)/len(purities)
'''
#raw_input()
print "Merging Clusters"
print "Number of Clusters before merge:", len(newClusters)
#.........这里部分代码省略.........