0

This is what I have tried:

# 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()

The shape of result is (640, 2), but what I keep getting is just a straight line.

Could someone please help?

Just to add, I ran a PCA on the data, and plotted a scatter plot of the data successfully. I am not sure how to extract all the eigenvalues, sort them and put into an eigenspectrum.

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()
user4476006
  • 21
  • 1
  • 6

1 Answers1

-3

To get all eigenvalues for a rectangular array, use:

numpy.linalg.eigvals

and for a square matrix use

numpy.linalg.eig
zx485
  • 28,498
  • 28
  • 50
  • 59
AnandJ
  • 346
  • 4
  • 15