小编K. *_*kow的帖子

SKLearn KMeans 收敛警告

我在一维数据集上使用 SKLearn 的 KMeans 聚类。我遇到的错误是,当我运行代码时,我得到一个ConvergenceWarning

ConvergenceWarning: Number of distinct clusters (<some integer n>) found smaller than n_clusters (<some integer bigger than n>). Possibly due to duplicate points in X.
  return_n_iter=True)
Run Code Online (Sandbox Code Playgroud)

除了源代码之外,我找不到任何相关内容,源代码并没有表明到底出了什么问题。我相信我的错误要么是因为我有一个一维数据结构,要么是因为我在 SKLearn 中使用一维数组的方式出了问题。这是有问题的代码:

def cluster_data(data_arr):
    """clusters the uas for a specific site"""
    d = 1.0
    k = 1
    inertia_prev = 1.0
    while k <= MAX and d > DELTA: 
        #max is the size of the input array, delta is .05
        kmean = KMeans(n_clusters=k)
        prediction = kmean.fit_predict(data_arr.reshape(-1, 1))
        #bug …
Run Code Online (Sandbox Code Playgroud)

python k-means scikit-learn

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

k-means ×1

python ×1

scikit-learn ×1