为什么使用Sklearn将错误的簇投射到PCA上?

时间:2015-04-06 23:05:06

标签: python scikit-learn cluster-analysis pca

我正在将我的聚类中心投影到2个主要组件上,但给出的图不在我的2组数据点的正确中心位置。我的代码如下。有谁看到我哪里出错了? PCA很好,但群集的其中一个数据点已经过时了。我会提到我的质心数据的一半是负数。我已经玩过反转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 :(得分:1)

fit_transform质心而不是transform