简体   繁体   English

在给定 x,y,z 坐标时使用 DBSCAN 算法使用 python 对 3D 点进行聚类

[英]Clustering the 3D points when given the x,y,z coordinates using DBSCAN algorithm using python

I'm trying to cluster some 3D points with the help of some given coordinates using DBSCAN algorithm with python.我试图在一些给定坐标的帮助下使用DBSCAN算法和 python 对一些 3D 点进行聚类。

ex:- given coordinates will be like follows例如:- 给定的坐标如下

  X      Y      Z

 [-37.530  3.109  -16.452]
 [40.247  5.483  -15.209]
 [-31.920 12.584  -12.916] 
 [-32.760 14.072  -13.749]
 [-37.100  1.953  -15.720] 
 [-32.143 12.990  -13.488]
 [-41.077  4.651  -15.651] 
 [-34.219 13.611  -13.090]
 [-33.117 15.875  -13.738]  e.t.c

I'm kind of new to programming and searching for an example script how to write the codes.我对编程和搜索如何编写代码的示例脚本有点陌生。 Can some one give a suggestion or an example?有人可以给出建议或例子吗? Thanks a lot in advance.非常感谢。

You can use sklearn.cluster.DBSCAN .您可以使用sklearn.cluster.DBSCAN In your case:在你的情况下:

import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cluster import DBSCAN

data = np.array([[-37.530, 3.109, -16.452],
                [40.247, 5.483, -15.209],
                [-31.920, 12.584, -12.916],
                [-32.760, 14.072, -13.749],
                [-37.100, 1.953, -15.720],
                [-32.143, 12.990, -13.488],
                [-41.077, 4.651, -15.651], 
                [-34.219, 13.611, -13.090],
                [-33.117, 15.875, -13.738]])

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(data[:,0], data[:,1], data[:,2], s=300)
ax.view_init(azim=200)
plt.show()

model = DBSCAN(eps=2.5, min_samples=2)
model.fit_predict(data)
pred = model.fit_predict(data)

fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(data[:,0], data[:,1], data[:,2], c=model.labels_, s=300)
ax.view_init(azim=200)
plt.show()

print("number of cluster found: {}".format(len(set(model.labels_))))
print('cluster for each point: ', model.labels_)

ouput输出

  • before clustering聚类前

在此处输入图片说明

  • after clustering聚类后

在此处输入图片说明

number of cluster found: 3
cluster for each point:  [ 0 -1  1  1  0  1 -1  1  1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python分离DBSCAN中每个簇的坐标(3D坐标) - Separating the coordinates(3D coordinates) for each cluster in DBSCAN using python 获取 3D 中平面给定 x 和 z 的 y 坐标 - Get y coordinates given x and z for a plane in 3D Python-如何在表面离散3D点(x,y,z)之后从给定的x,y获取z值 - Python - How to get z value from given x, y after surface discrete 3D points (x,y,z) 3d将x,y,z坐标转换为3d numpy数组 - 3d coordinates x,y,z to 3d numpy array 给定 x,y,z 坐标的数据,我将如何在 Matplotlib 中制作 3D 表面 plot? - How would I make a 3D surface plot in Matplotlib given this data of x,y,z coordinates? 如何获得轮廓 plot 和 3D plot 使用 z1587383CF8C21507D06FB 的 zDDDA 和 a set5ZEF3 列的起始点来表示? - How can I obtain a contour plot and a 3D plot using Matplotlib starting from a set of 3 columns representing x,y and z points? 如何在Python中获取每次单击的3D模型的(x,y,z)坐标? - How to get the (x,y,z) coordinates of a 3D model of every click in Python? Python:创建 X、Y 坐标和相应的计算 Z 值的网格以生成 XYZ 的 3D 数组 - Python: Creating a Grid of X,Y coordinates and corresponding calculated Z values to result in a 3D array of XYZ 给定一组在(X,Y,Z)坐标中定义的点,在任意(X,Y)处插值Z值 - Given a set of points defined in (X, Y, Z) coordinates, interpolate Z-value at arbitrary (X, Y) 在 Python 中使用循环创建 x、y、z 坐标列表 - Create list of x,y,z coordinates using loop in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM