Yes, setting initial centroids via init should work. Here's a quote from scikit-learn documentation: init : {‘k-means++’, ‘random’ or an ndarray} Method for initialization, defaults to ‘k-means++’: If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. (n_clusters, n_features)指的是什么形状? What is the shape (n_clusters, n_features) referring to?形状要求意味着init必须精确地包含n_clusters行,并且每行中的元素数量应与actual_data_points的维数匹配:The shape requirement means that init must have exactly n_clusters rows, and the number of elements in each row should match the dimensionality of actual_data_points:>>> init = np.array([[-0.12, 0.939, 0.321, 0.011], [0.0, 0.874, -0.486, 0.862], [0.0, 1.0, 0.0, 0.033], [0.12, 0.939, 0.321, -0.7], [0.0, 1.0, 0.0, -0.203], [0.12, 0.939, -0.321, 0.25], [0.0, 0.874, 0.486, -0.575], [-0.12, 0.939, -0.321, 0.961]], np.float64)>>> init.shape[0] == 8True # n_clusters>>> init.shape[1] == actual_data_points.shape[1]True # n_features 什么是n_features? What is n_features? n_features是样品的尺寸.例如,如果要在2D平面上对点进行聚类,则n_features将为2.n_features is the dimensionality of your sample. For instance, if you were to cluster points on a 2D plane, n_features would be 2. 这篇关于scikit-学习kmeans聚类的初始质心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!