2015-04-06 56 views
0

我正在將我的聚類中心投影到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) 
+1

你可以發佈圖片嗎? –

+0

我沒有足夠的積分... – user4476006

+0

您可以發佈一個鏈接imgur ... –

回答

1

fit_transform其中荷蘭國際集團的重心,而不是transform

+0

我需要四個最後的觀點,從我的21維聚類中心。當我使用變換時,圖表仍然顯示相同,並且我的羣集出來:''羣集:[[-3.73604149e-01 -7.88968144e-02 -2.39775253e-04 -2.98255905e-03-03-O3 -5.53224119e- 03 -3.71999147e-03 -2.40050141e-03 -3.85699695e-04 6.72346604e-03 4.83367176e-03 7.86504453e-04 -3.69889640e-03 3.47965218e-04 -3.10482175e-03 -1.61504788e-03 1.68468915 e-03 -9.73136520e-04 5.83231053e-04 -8.74801939e-04 -2.84281009e-04 -2.53746653e-04]''(對於2個簇) – user4476006

+0

使用fit_transform,它變爲:'簇:[[ -1.35841000e + 00 4.29736603e-16] [1.35841000e + 00 4.29736603e-16]]'' – user4476006

+0

該圖有兩個基本上有兩個粗糙的均勻中心點。羣集應該在每個中間,但是一個完全不在中心...... – user4476006