日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python聚类dbscan案例经纬度_用DBSCAN聚类经纬度坐标

發布時間:2024/9/19 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python聚类dbscan案例经纬度_用DBSCAN聚类经纬度坐标 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用基于密度的聚類算法,計算坐標點聚集地,很好用。

import pandas as pd

import numpy as np

from sklearn.cluster import DBSCAN

from sklearn import metrics

from sklearn.cluster import KMeans

import os

def dbscan(input_file):

columns=['lon','lat']

in_df = pd.read_csv(input_file, sep=',', header=None, names=columns)

#print(in_df.head(10))

#represent GPS points as (lon, lat)

coords = in_df.as_matrix(columns=['lon','lat'])

#earth's radius in km

kms_per_radian = 6371.0086

#define epsilon as 0.5 kilometers, converted to radians for use by haversine

#This uses the 'haversine' formula to calculate the great-circle distance between two points

# that is, the shortest distance over the earth's surface

# http://www.movable-type.co.uk/scripts/latlong.html

epsilon = 0.5 / kms_per_radian

# radians() Convert angles from degrees to radians

db = DBSCAN(eps=epsilon, min_samples=15, algorithm='ball_tree', metric='haversine').fit(np.radians(coords))

cluster_labels = db.labels_

# get the number of clusters (ignore noisy samples which are given the label -1)

num_clusters = len(set(cluster_labels) - set([-1]))

print( 'Clustered ' + str(len(in_df)) + ' points to ' + str(num_clusters) + ' clusters')

# turn the clusters in to a pandas series

#clusters = pd.Series([coords[cluster_labels == n] for n in range(num_clusters)])

#print(clusters)

kmeans = KMeans(n_clusters=1, n_init=1, max_iter=20, random_state=20)

for n in range(num_clusters):

# print('Cluster ', n, ' all samples:')

one_cluster = coords[cluster_labels == n]

#print(one_cluster[:1])

#clist = one_cluster.tolist()

#print(clist[0])

kk = kmeans.fit(one_cluster)

print(kk.cluster_centers_)

def main():

path = './datas'

filelist = os.listdir(path)

for f in filelist:

datafile = os.path.join(path,f)

print(datafile)

dbscan(datafile)

if __name__ == '__main__':

main()

下面幾個博客,寫的很好:

https://www.cnblogs.com/pinard/p/6208966.html

http://shiyanjun.cn/archives/1288.html

https://www.biaodianfu.com/dbscan.html

總結

以上是生活随笔為你收集整理的python聚类dbscan案例经纬度_用DBSCAN聚类经纬度坐标的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。