本文整理汇总了Python中cluster.Cluster.add_point方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.add_point方法的具体用法?Python Cluster.add_point怎么用?Python Cluster.add_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.add_point方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dbscan
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import add_point [as 别名]
def dbscan(self, data):
self.init_params()
self.data = data
## Setting up the plot
fig = plt.figure()
axis_proj = 'rectilinear'
if self.dim > 2:
axis_proj = '%dd' % self.dim
ax = fig.add_subplot(111, projection = axis_proj)
#default noise cluster
noise = Cluster('Noise', self.dim)
self.clusters.add(noise)
for point in data:
if point not in self.visited:
self.visited.append(point)
neighbour_pts = self.region_query(point)
if len(neighbour_pts) < self.min_pts:
noise.add_point(point)
else:
name = 'cluster-%d' % self.cluster_count
new_cluster = Cluster(name, self.dim)
self.cluster_count += 1
self.expand_cluster(new_cluster, point, neighbour_pts)
if self.dim == 2:
ax.scatter(new_cluster.get_X(), new_cluster.get_Y(), c = self.color[self.cluster_count % len(self.color)],
marker = 'o', label = name)
elif self.dim == 3:
ax.scatter(new_cluster.get_X(), new_cluster.get_Y(), new_cluster.get_Z(), marker = 'o',
c = self.color[self.cluster_count % len(self.color)], label = name)
ax.hold(True)
if len(noise.get_points()) != 0:
if self.dim > 2:
ax.scatter(noise.get_X(), noise.get_Y(), noise.get_Z(), marker = 'x', label = noise.name)
else:
ax.scatter(noise.get_X(), noise.get_Y(), marker = 'x', label = noise.name)
print ("Number of clusters found: %d" % self.cluster_count)
ax.hold(False)
ax.legend(loc='lower left')
ax.grid(True)
plt.title(r'DBSCAN Clustering', fontsize=18)
plt.show()