def cluster(lonlat_list):
#dic_lonlat = {}
#for i in range(len(tr_lonlat_list)):
# lon = tr_lonlat_list[i][0]
# lat = tr_lonlat_list[i][1]
# key = str(lon)+":"+str(lat)
# if key not in dic_lonlat.keys():
# lonlat_list.append([lon,lat])
# dic_lonlat[key] = 1
#for i in range(len(te_lonlat_list)):
# lon = te_lonlat_list[i][0]
# lat = te_lonlat_list[i][1]
# key = str(lon)+":"+str(lat)
# if key not in dic_lonlat.keys():
# lonlat_list.append([lon,lat])
# dic_lonlat[key] = 1
#lonlat_list = np.array(lonlat_list)
#kmeans = KMeans(n_clusters=NUM_CLUSTERS,n_jobs=-1).fit(lonlat_list)
mf = MeanShift().fit(lonlat_list)
lonlat_cluster_dict = {}
for i in range(lonlat_list.shape[0]):
key = str(lonlat_list[i][0])+":"+str(lonlat_list[i][1])
lonlat_cluster_dict[key] = mf.labels_[i]
#for i in range(NUM_CLUSTERS):
# count = 0
# for k,v in lonlat_cluster_dict.items():
# if i == v:
# count += 1
# print('cluster:'+str(i)+'\tcount:'+str(count))
return lonlat_cluster_dict
评论列表
文章目录