如何对 python 中的点列表使用 DBSCAN 算法

How to use DBSCAN algorithm for a list of points in python

我不熟悉图像处理和 python 编码。 我已经检测到图像中的许多特征并将它们各自的像素位置放置在列表格式中。

My_list = [(x1,y1),(x2,y2),......,(xn,yn)]

我想用DBSCAN算法从以下几点组成聚类。 目前正在使用 sklearn.cluster 为 python 导入 DBSCAN 函数中的构建。 如果点的当前格式不兼容想知道哪个是?

当前格式当前面临的错误:

C:\Python\python.exe "F:/opencv_files/dbscan.py"  
**Traceback (most recent call last):**
  **File "**F:/opencv_files/dbscan.py**", line 83, in <module>  
    db = DBSCAN(eps=0.5, min_samples=5).fit(X) # metric=X)**  
  **File "**C:\Python\lib\site-packages\sklearn\cluster\dbscan_.py**", line 282, in fit  
    X = check_array(X, accept_sparse='csr')  
  File "**C:\Python\lib\site-packages\sklearn\utils\validation.py**", line 441, in check_array  
    "if it contains a single sample.".format(array))  
ValueError: Expected 2D array, got 1D array instead:  
array=[].  
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.**

您的数据是 tuplelist。在这个结构中没有什么可以阻止你用它做疯狂的事情,比如在那里有不同的长度。另外,这是一种非常缓慢且内存效率低下的数据保存方式,因为所有内容都被装箱为 Python 对象。

只需调用 data = numpy.array(data) 即可将您的数据转换为高效的多维数值数组。然后这个数组将有一个 shape.