我正在將我的聚類中心投影到2個主要組件上,但給出的圖不在我的2組數據點的正確中心位置。我的代碼如下。有沒有人看到我要去哪裏錯了? PCA很好,但集羣的其中一個數據點是離開的。我會提到我的一半質心數據點是負面的。我玩過反轉pca轉換,真的不知道錯誤來自哪裏。任何幫助是極大的讚賞!爲什麼使用Sklearn將錯誤的簇投影到PCA上?
import numpy as np
import sklearn
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
data = normalize(key)
key_N=normal(key,key)
pca=PCA(n_components=21)
pca.fit(data[:,0:-1])
keytrain_T = pca.transform(data[:,0:-1])
kmeans = KMeans(n_clusters=2, init='k-means++', n_init=100, max_iter=300,
tol=0.0001, precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1)
kmeans.fit(data[:,0:-1])
centroid = cluster_centers_
print("The centroids:",centroid)
# Project the cluster points to the two first principal components
clusters = pca.fit_transform(centroid)
print("The clusters:",clusters)
你可以發佈圖片嗎? –
我沒有足夠的積分... – user4476006
您可以發佈一個鏈接imgur ... –