gpt4 book ai didi

python - 是否可以使用 k-means 在 scikit/sklearn learn 中使用的 K++ 初始化过程?

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

我正在阅读 k-means 的文档我看到它使用 k++作为初始化。是否可以使用sci-py中实现的k++初始化函数?

阅读他们的文档,我认为唯一的方法是使用 K-means 算法,但不要训练任何次数的迭代,如下所示:

N = 1000 #data set size
D = 2 # dimension
X = np.random.rand(N,D)
kmeans = sklearn.cluster.KMeans(n_clusters=8, init='k-means++', n_init=1, max_iter=0)
ceneters_k_plusplus = kmeans.fit(X)

这可行吗?或者有没有直接的方法来正确使用他们的库? (在他们的文档中找不到它)

经过一番痛苦和流血之后,我设法让它运行(如果它正确的话,我认为不是 100%,但它返回一个 numpy 数组):

import sklearn
import sklearn.cluster.k_means_
import numpy as np
#from ..utils.extmath import row_norms, squared_norm
from sklearn.utils.extmath import row_norms, squared_norm
from sklearn.utils import check_random_state

X = np.random.rand(10,3)
n_clusters = 4
random_state = None
random_state = check_random_state(random_state)
x_squared_norms = row_norms(X, squared=True)

centers = sklearn.cluster.k_means_._k_init(X, n_clusters, random_state=random_state,x_squared_norms=x_squared_norms)
print centers

最佳答案

它没有在 scipy 中实现。有一个拉取请求实现了它,但它停滞了。 https://github.com/scipy/scipy/pull/4119

关于python - 是否可以使用 k-means 在 scikit/sklearn learn 中使用的 K++ 初始化过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38191930/

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