bokeh_clustering.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:WebAppEx 作者: karlafej 项目源码 文件源码
def update():
    # Get the current slider values
    N = clusters.value
    x_var = axis_map[x_axis.value]
    y_var = axis_map[y_axis.value]

    k_means = KMeans(n_clusters=N)
    k_means.fit(iris.data) 
    centroids = k_means.cluster_centers_

    palette = sns.palettes.color_palette('hls', N)
    colormap = np.array(palette.as_hex())[k_means.labels_] # as hex is necessary for bokeh to render the colors properly.

    plot.xaxis.axis_label = x_axis.value
    plot.yaxis.axis_label = y_axis.value

    source.data = dict(
        x=iris.data[:,x_var],
        y=iris.data[:,y_var],
        colors=colormap)
    centers.data = dict(
        cx=centroids[:,x_var],
        cy=centroids[:,y_var])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号