我已经为我的数据应用了 Kmeans 聚类并尝试用 folium 映射聚类
地图的代码是:
Toronto_map_clusters = folium.Map(location=[latitude, longitude], zoom_start=11)
x = np.arange(kclusters)
ys = [i + x + (i*x)**2 for i in range(kclusters)]
colors_array = cm.rainbow(np.linspace(0, 1, len(ys)))
rainbow = [colors.rgb2hex(i) for i in colors_array]
markers_colors = []
for lat, lon, poi, cluster in zip(Toronto_merged['Latitude'], Toronto_merged['Longitude'], Toronto_merged['Neighborhood'], Toronto_merged['Cluster Labels']):
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(Toronto_map_clusters)
Toronto_map_clusters
我得到以下错误:
TypeError Traceback (most recent call last)
<ipython-input-81-5c051a345a95> in <module>()
16 radius=5,
17 popup=label,
***18 color=rainbow[cluster-1]***
19 fill=True,
*** 20 fill_color=rainbow[cluster-1]***
TypeError: list indices must be integers or slices, not float
地图显示没有第 18 行和第 20 行,但没有分隔簇颜色(因为缺少颜色值)。
感谢您的任何建议!