An example showing the plot_pca_component_variance method used by a scikit-learn PCA object

In this example we'll use scikit-plot's sklearn.decomposition.plot_pca_component_variance on our PCA algorithm to see the variance in our feature embeddings. First, we'll create an instance of the PCA algorithm, then fit our model with the data, and pass this fitten instance into our scikit-plot method.


In [1]:
from sklearn.decomposition import PCA
from sklearn.datasets import load_digits as load_data
import matplotlib.pyplot as plt

# Import scikit-plot
import scikitplot as skplt

%pylab inline
pylab.rcParams['figure.figsize'] = (14, 14)


Populating the interactive namespace from numpy and matplotlib

In [2]:
# Load the dataset
X, y = load_data(return_X_y=True)

# Create PCA instance then fit
pca = PCA(random_state=1)
pca.fit(X)


Out[2]:
PCA(copy=True, iterated_power='auto', n_components=None, random_state=1,
  svd_solver='auto', tol=0.0, whiten=False)

In [3]:
# Plot!
skplt.decomposition.plot_pca_component_variance(pca)
plt.show()