使用DBSCAN进行轨迹聚类

问题描述 投票:0回答:1

我正在尝试确定轨迹的路径。我有一条经纬度长的轨迹。

这是我的代码:

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

我的输入是一个带有其他变量的DataFrame。当我运行过程时,它使我出现以下错误:

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,这是我按时间点排序的中间点。

python dataframe scikit-learn sklearn-pandas dbscan
1个回答
0
投票

数据的特征包括纬度和经度。由于这是一个熊猫数据框,因此您可以在这种情况下切片要用于执行聚类的功能。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.