将叶片簇标签点-1设置为灰色,其余的自动设置

问题描述

DBSCAN之后,我得到了24个聚类,为每个聚类代码颜色不佳的271个地理坐标分配聚类标签后,network_cluster包含了从-1到22的24个标签,我需要将-1设置为灰色噪声,其余的标签自动包含在dataframe列Healthcenters_Network ['network_cluster']

%%time
# use metric=precomputed to fit model to the sparse network-based distance matrix
db = DBSCAN(eps=eps,min_samples=minpts,metric='precomputed')
firms['network_cluster'] = db.fit_predict(ndm_sparse)

,然后合并包含network_clusters标签和 卫生中心数据框

#Create a dataframe that includes socioeconomic index from these healthcenters
# -- FUNCTION -- Merge dataframes
Healthcenters_Network = pd.merge(left=Healthcenters_merged,right=HC,left_on='geom',right_on='geom')
Healthcenters_Network.head()

最后画出群集

# create map
map_Network = folium.Map(location=[latitude,longitude],zoom_start=11,control_scale = True)

# set color scheme for the clusters
x = np.arange(db.labels)
ys = [i + x + (i*x)**2 for i in range(db.labels)]
colors_array = cm.rainbow(np.linspace(0,1,len(ys)))
rainbow = [colors.rgb2hex(i) for i in colors_array]

map_Network.choropleth(ageb,# AGEB geojson of QuereTaro City
             data=Index,# my dataset
             columns=['CVE GEO','Socioeconomic Index'],# CVE GEO is here for matching the geojson CVEGEO,Socioeconomic index is the column that changes the color of ageb
             key_on='feature.properties.cvegeo',# this path contains cvegeo in str type,this cvegeo should match with our CVE GEO column
             fill_color='YlGnBu',fill_opacity=0.7,line_opacity=0.3,legend_name='Socioeconomic index')

# add markers to the map
markers_colors = []
for lat,lon,poi,cluster in zip(Healthcenters_Network['Venue Latitude'],Healthcenters_Network['Venue Longitude'],Healthcenters_Network['Healthcenter'],Healthcenters_Network['network_cluster']):
    label = folium.Popup(str(poi) + ' Cluster ' + str(cluster),parse_html=True)
    folium.CircleMarker(
        [lat,lon],radius=5,popup=label,color=rainbow[cluster-1],fill=True,fill_color=rainbow[cluster-1],fill_opacity=0.7).add_to(map_Network)
       
map_Network

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)