I use the following code:
# Fit PCA
pca = PCA(n_components=3)
pca.fit(data)
# Plot
plt.plot(range(0,3), pca.explained_variance_ratio_)
plt.ylabel('Explained Variance')
plt.xlabel('Principal Components')
plt.title('Explained Variance Ratio')
plt.show()
pca.explained_variance_ratio_
From this I obtain the following graph:
and array([0.92540219, 0.06055593, 0.01404188])
What I dont understand is why it is showing just two principal components? And should it be 92.54% (of info explained by 1st component), while in the graph it is less the 20%? Please, help me with this misunderstanding.
It is showing all threes components. The values of pca.explained_variance_ratio_ are plotted in your graph at 0, 1 and 2 on the x axis. First value is at (0, 0.92540219), second at (1, 0.06055593) and last at (2, 0.01404188).