KMeansオブジェクトに適合した場合は、cluster_centers_
という属性があります。あなたはきれいなクラスタ中心を持つ新しいオブジェクトをしたい場合は、だから、
cls.cluster_centers_ = new_cluster_centers
をちょうど次のようなものを実行します:あなたは、直接このような何かを行うことによって、それを更新することができ
cls = KMeans().fit(X)
cls2 = cls.copy()
cls2.cluster_centers_ = new_cluster_centers
そして今、予測関数では、オブジェクトにcluster_centers_という名前のヌル以外の属性があることだけがチェックされるため、予測関数を使用できます。
def predict(self, X):
"""Predict the closest cluster each sample in X belongs to.
In the vector quantization literature, `cluster_centers_` is called
the code book and each value returned by `predict` is the index of
the closest code in the code book.
Parameters
----------
X : {array-like, sparse matrix}, shape = [n_samples, n_features]
New data to predict.
Returns
-------
labels : array, shape [n_samples,]
Index of the cluster each sample belongs to.
"""
check_is_fitted(self, 'cluster_centers_')
X = self._check_test_data(X)
x_squared_norms = row_norms(X, squared=True)
return _labels_inertia(X, x_squared_norms, self.cluster_centers_)[0]
clean_c luster_arrayは、あなたが再びフィットした後のように見え、clusters_centers_はどのように見えますか? –
センターが形状(52,2E5)であるので、私はここでそれを示すことはできません。彼らはあなたの質問に答えるために異なっています。 –
@ValentinCalommeモデルをフィッティングした後、 'clean_cluster_array' を' clusters_centers_'に渡すことをお勧めします。これはセンターを書き直すべきです。しかし、私はこのモデルフィッティングを完全にバイパスしたいと思います。これを試して結果を投稿します。 –