我正在将我的聚类中心投影到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 ... –