gpt4 book ai didi

python - 使用肘部方法和 K-Means 聚类找到最佳聚类数

转载 作者:行者123 更新时间:2023-12-05 09:09:25 26 4
gpt4 key购买 nike

我正在编写一个程序,我需要对其应用 K-means 聚类到一些 >200、300 元素数组的数据集。有人能给我提供一个代码链接吗?1.通过肘法求k2. 应用 k 均值方法并获取质心数组

我自己搜索了上面的内容,但没有找到任何对代码有明确解释的内容。附言我正在 Google Colab 上工作,所以如果有相同的特定方法,请提出建议


我尝试了下面的代码,但是,我不断收到以下错误-

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

TypeError: float() argument must be a string or a number, not 'list'


The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last)

<ipython-input-70-68e300fd4bf8> in <module>()
24
25 # step 1: find optimal k (number of clusters)
---> 26 find_best_k()
27

3 frames

/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
83
84 """
---> 85 return array(a, dtype, copy=False, order=order)
86
87

ValueError: setting an array element with a sequence.

最佳答案

作为 Roohollah 回答的补充:请注意,用于查找 K-Means 最佳簇数的肘部方法纯粹是视觉上的,结果可能不明确。因此,您可能希望将它与剪影分析结合起来,例如,在以下文章中所描述的: Choosing the appropriate number of clusters (RealPython) , Silhouette method - including an implementation example in Python (TowardsDataScience) , Silhouette analysis example (Scikit-learn) , Silhouette (Wikipedia) .

关于python - 使用肘部方法和 K-Means 聚类找到最佳聚类数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62443970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com