plot_pca_component_variance#

scikitplot.api.decomposition.plot_pca_component_variance(clf, *args, target_explained_variance=0.75, model_type=None, title='Cumulative Explained Variance Ratio by Principal Components', ax=None, fig=None, figsize=None, title_fontsize='large', text_fontsize='medium', x_tick_rotation=0, **kwargs)[source]#

Plots PCA components’ explained variance ratios. (new in v0.2.2)

Added in version 0.2.2.

Parameters:
clfobject

PCA instance that has the explained_variance_ratio_ attribute.

titlestr, optional, default=’Cumulative Explained Variance Ratio by Principal Components’

Title of the generated plot.

target_explained_variancefloat, optional, default=0.75

Looks for the minimum number of principal components that satisfies this value and emphasizes it on the plot.

axmatplotlib.axes.Axes, optional, default=None

The axes upon which to plot the curve. If None, a new set of axes is created.

figsizetuple of int, optional, default=None

Tuple denoting figure size of the plot (e.g., (6, 6)).

title_fontsizestr or int, optional, default=’large’

Font size for the plot title. Use e.g., “small”, “medium”, “large” or integer-values.

text_fontsizestr or int, optional, default=’medium’

Font size for the text in the plot. Use e.g., “small”, “medium”, “large” or integer-values.

x_tick_rotationint, optional, default=0

Rotates x-axis tick labels by the specified angle.

Added in version 0.3.9.

Returns:
matplotlib.axes.Axes

The axes on which the plot was drawn.

Examples

>>> from sklearn.decomposition import PCA
>>> from sklearn.datasets import load_digits as data_10_classes
>>> import scikitplot as skplt
>>> X, y = data_10_classes(return_X_y=True, as_frame=False)
>>> pca = PCA(random_state=0).fit(X)
>>> skplt.decomposition.plot_pca_component_variance(pca, target_explained_variance=0.95);

(Source code, png)

PCA Components Variances
>>> from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
>>> from sklearn.datasets import load_digits as data_10_classes
>>> import scikitplot as skplt
>>> X, y = data_10_classes(return_X_y=True, as_frame=False)
>>> clf = LinearDiscriminantAnalysis().fit(X, y)
>>> skplt.decomposition.plot_pca_component_variance(clf);

(Source code, png)

LDA Components Variances