基于DBSCAN的轨迹聚类

2024-06-03 00:15:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图确定轨迹上的路径。我有一条长点的轨迹

这是我的密码:

def clustersDBSCAN(data):
    from sklearn.cluster import DBSCAN
    a=data
    coords = a['Long']
    coords['Lat'] = a['Lat']
    coords = coords.to_numpy(coords)
    kms_per_radian = 6371.0088
    epsilon = 0.02 / kms_per_radian
    db = DBSCAN(eps=epsilon, min_samples=1, algorithm='ball_tree', metric='haversine').fit(np.radians(coords))
    cluster_labels = db.labels_
    a['clusters']=cluster_labels
    return a

我的enter是一个带有一些其他变量的数据帧。当我运行过程时,会出现以下错误:

Traceback (most recent call last):

  File "<ipython-input-160-1bb326319131>", line 19, in <module>
    TestEtude1 = clustersDBSCAN(TestEtude1)

  File "<ipython-input-160-1bb326319131>", line 14, in clustersDBSCAN
    db = DBSCAN(eps=epsilon, min_samples=1, algorithm='ball_tree', metric='haversine').fit(np.radians(coords))

TypeError: loop of ufunc does not support argument 0 of type float which has no callable radians method

编辑

我的数据如下所示:

Lat Long    Type de point
136701  53.87030526540526   7.305133353275677       1
136702  53.870307858385225  7.305140443133933       0
136703  53.87031363700621   7.305150308822018       0
136704  53.87031595061333   7.305142298625614       0
136705  53.87032064860515   7.305141557055512       0
136706  53.870326088345934  7.305156457965349       2
136707  53.87030945094248   7.305160487693352       1
136708  53.870349819652134  7.305194852863318       0
136709  53.870340745293994  7.305186559915658       0
136710  53.8702835623423    7.305181727204434       0

点1的类型表示轨迹的原点,点2的类型表示轨迹的终点。在1和2之间,有0类型的点,它们是按时间点排序的中间点


Tags: 类型dbdatalabels轨迹coordsdbscanlong
1条回答
网友
1楼 · 发布于 2024-06-03 00:15:43

数据的特征包括纬度和经度。因为它是一个数据帧,所以在本例中,您可以切片到要用于执行集群的功能

查看代码,可以看出所传递的功能不正确,您可以执行以下操作:

fit()中用np.radians(data[["Lat","Long"]])替换np.radians(coords),它应该可以工作

相关问题 更多 >