【问题标题】:How do I visualize the output of K-modes clustering algorithm in Javascript?如何在 Javascript 中可视化 K-modes 聚类算法的输出?
【发布时间】:2026-01-15 04:45:02
【问题描述】:

我有集群详细信息的输出,如下所示。

from collections import Counter, defaultdict
print(Counter(kmodess.labels_))

输出是集群数和属于它的用户数: Counter({1: 10500, 2: 400, 3:10})

我想展示如下所示的内容。这在 Python 中是否可行,或者如果我必须使用 javascript,我该如何进行这种表示?

我从下面的 matplot.lib 链接中引用了代码。 plot a circle with pyplot

但是,我如何提供输入并根据它显示圆圈?

【问题讨论】:

    标签: javascript python matplotlib scikit-learn visualization


    【解决方案1】:
    【解决方案2】:

    如果您已经知道如何使用 pyplot 执行此操作,则可以将其保存到文件中并静态提供,无需 js。

    要将你的情节转储到文件中:

    plt.savefig('clusters.png')
    

    然后使用 HTML img 标签:

    <!DOCTYPE html>
    <html>
      <head>
        <title>Display my Matplotlib Image</title>
      </head>
      <body>
        <img src="clusters.png" alt="Large and small circles representing clusters">
      </body>
    </html>
    

    要查看结果,只需用浏览器打开上面的 html 文件即可。

    【讨论】:

    • 我试过 matplotlib.pyplot。我找到了一种使用饼图而不是单独的圆圈来表示这一点的方法。非常感谢您的帮助。