2015-04-02 86 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