深圳画册设计师,广州网站优化推广方案,章丘营销型网站设计公司,德州网站推广ESDA in PySAL (1) 利用 A-DBSCAN 聚类点并探索边界模糊性
在本例中,我们将以柏林的 AirBnb 房源样本为例,说明如何使用 A-DBSCAN (Arribas-Bel et al., 2019)。A-DBSCAN 可以让我们做两件事: 识别高密度 AirBnb 房源集群并划定其边界探索这些边界的稳定性%matplotlib inli…ESDA in PySAL (1) 利用 A-DBSCAN 聚类点并探索边界模糊性
在本例中,我们将以柏林的 AirBnb 房源样本为例,说明如何使用 A-DBSCAN (Arribas-Bel et al., 2019)。A-DBSCAN 可以让我们做两件事:
识别高密度 AirBnb 房源集群并划定其边界探索这些边界的稳定性%matplotlib inlineimport pandas
import geopandas
import numpy as np
import contextily as cx
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
from libpysal.cg.alpha_shapes import alpha_shape_autoimport sys
sys.path.append("../")
try:from esda.adbscan import ADBSCAN, get_cluster_boundary, remap_lbls
# This below can be removed once A-DBSCAN is merged into `esda`
except:print("Import from local folder...")import syssys.path.append("../esda")from adbscan import ADBSCAN, get_cluster_boundary, remap_lbls数据
我们将使用 Inside Airbnb 中的柏林提取数据。这与 Scipy 2018 tutorial on Geospatial data analysis with Python中使用的数据集相同。
tab = pandas.read_csv("data/berlin-listings.csv")
tab.head(2)Unnamed: 0idlisting_urlscrape_idlast_scrapednamesummaryspacedescriptionexperiences_offered...review_scores_valuerequires_licenselicensejurisdiction_namesinstant_bookablecancellation_policyrequire_guest_profile_picturerequire_guest_phone_verificationcalculated_host_listings_countreviews_per_month0017260587https://www.airbnb.com/rooms/17260587201705072222352017-05-08Kunterbuntes Zimmer mit eigenem Bad für jedermannMeine Unterkunft ist gut für paare, alleinreis...NaNMeine Unterkunft ist gut für paare, alleinreis...none...10.0fNaNNaNtflexibleff32.001117227881https://www.airbnb.com/rooms/17227881201705072222352017-05-08Modernes Zimmer in Berlin PankowEs ist ein schönes gepflegtes und modernes Zim...Das Haus befindet sich direkt vor eine Tram Ha...Es ist ein schönes gepflegtes und modernes Zim...none...10.0fNaNNaNtflexibleff11.292 rows × 96 columns
原始数据集包括 20,000 多个观测值:
tab.shape(20053, 96)为了让图解在任何硬件上运行得更快一些,让我们随机抽取 10%的样本,即随机抽取 2,000 个属性:
tab = tab.sample(n=2000, random_state=1234)为方便起见,我们将其转换为 “GeoDataFrame”,其中的几何图形是根据原始表格中的长/纬度列建立的:
db_ll = geopandas.GeoDataFrame(tab,geometry=geopandas.points_from_xy(tab.longitude, tab.latitude),crs={'init': 'epsg:4326'})/home/serge/anaconda3/envs/analytical/lib/python3.7/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=authority:code' syntax is deprecated. 'authority:code' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6return _prepare_from_string(" ".join(pjargs))因为我们要运行一个依赖于距离的算法,所以我们需要能够在投影平面上计算这些距离。我们使用为德国设计的ETRS89投影来代替原始的长/纬度坐标,并以米为单位:
db = db_ll.to_crs(epsg=5243)*现在我们可以将数据集可视化了:
ax = db.plot(markersize=0.1, color='orange')
cx.add_basemap(ax, crs=db.crs.to_string());