2015-04-02 142 views
0

這是我曾嘗試:如何繪製python中的特徵譜?

# Show the eigenspectrum 
eigenvalues = pca.explained_variance_ 
print("The eigenvalues:\n\t", eigenvalues) 

idx = eigenvalues.argsort() 
print(idx) 

plt.plot(idx, color='green', marker='D') 
plt.ylabel('Eigenspectrum') 
plt.show() 

結果的形狀是(640,2),但我不斷收到只是一條直線。

有人可以幫忙嗎?

爲了補充,我在數據上運行了PCA,併成功繪製了數據的散點圖。我不知道如何提取所有的特徵值,將它們分類並放入一個特徵譜中。

pca=PCA(n_components=2) 
pca.fit(keytrain[:,0:-1]) 
keytrain_T=pca.transform(keytrain[:,0:-1]) 

print("Shape of result:", keytrain_T.shape) 

# plot the results along with the labels 
fig, ax = plt.subplots() 
im = ax.scatter(keytrain_T[:, 0], keytrain_T[:, 1], c=y) 
fig.colorbar(im); 
plt.show() 
+0

那麼,是什麼打印,當你做'打印(IDX )'? – 2015-04-02 21:50:28

+0

特徵值: \t [0.04992169 0.03185585] – user4476006 2015-04-02 21:55:13

+0

如果'idx'只有兩個值,那麼當您繪製它時爲什麼會看到超過2個點(這是一條直線)? – 2015-04-02 21:56:47

回答

0

要獲得全部特徵的矩形陣列,使用:

numpy.linalg.eigvals 

和方陣使用

numpy.linalg.eig