pca сюжет по данным kmeans - PullRequest
       36

pca сюжет по данным kmeans

0 голосов
/ 11 декабря 2019

Я сгруппировал свои данные (используя kmeans) с большими измерениями в Python, и после того, как я хотел бы построить точечный график с использованием PCA. Но мой сюжет очень странный, и я не понимаю, почему? Также я обнаружил, что компоненты PCA имеют отрицательные значения. Может кто-нибудь посоветовать, как построить правильный точечный график? Спасибо enter image description here

#Normalize data
scaler = MinMaxScaler()
new2 = pd.DataFrame(scaler.fit_transform(dd))
#Kmeans
kmeans = KMeans(n_clusters=5)
kmeans.fit(new2)
clusters = kmeans.predict(new2)
#PCA and scatter plot
pca = PCA(n_components=2)
principalComponents = pca.fit_transform(new2)
principalDf = pd.DataFrame(data = principalComponents
             , columns = ['principal component 1', 'principal component 2'])
finalDf = pd.concat([principalDf, new2[['Cluster']]], axis = 1)

fig = plt.figure(figsize = (10,10))
ax = fig.add_subplot(1,1,1) 
ax.set_xlabel('Principal Component 1', fontsize = 15)
ax.set_ylabel('Principal Component 2', fontsize = 15)
ax.set_title('2 component PCA', fontsize = 20)
targets = ['0','1','2','3','4']
colors = ['red','blue','black','pink','green']
for target, color in zip(targets,colors):
    indicesToKeep = finalDf['Cluster'] == target
    ax.scatter(finalDf.loc[indicesToKeep, 'principal component 1']
               , finalDf.loc[indicesToKeep, 'principal component 2']
               , c = color
               , s = 50)
ax.legend(targets)
ax.grid()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...