bff.plot.plot_pca_explained_variance_ratio¶
-
bff.plot.
plot_pca_explained_variance_ratio
(pca, label_x='Number of components', label_y='Cumulative explained variance', title='PCA explained variance ratio', hline=None, ax=None, lim_x=None, lim_y=None, grid=None, figsize=10, 4, dpi=80, style='default', **kwargs)¶ Plot the explained variance ratio of PCA.
PCA must be already fitted.
- Parameters
pca (sklearn.decomposition.PCA) – PCA object to plot.
label_x (str, default 'Number of components') – Label for x axis.
label_y (str, default 'Cumulative explained variance') – Label for y axis.
title (str, default 'PCA explained variance ratio') – Title for the plot (axis level).
hline (float, optional) – Horizontal line (darkorange) to draw on the plot (e.g. at 0.8 to see the number of components needed to keep 80% of the variance).
ax (plt.axes, optional) – Axes from matplotlib, if None, new figure and axes will be created.
lim_x (Tuple[TNum, TNum], optional) – Limit for the x axis.
lim_y (Tuple[TNum, TNum], optional) – Limit for the y axis.
grid (str, optional) – Axis where to activate the grid (‘both’, ‘x’, ‘y’). To turn off, set to None.
figsize (Tuple[int, int], default (10, 4)) – Size of the figure to plot.
dpi (int, default 80) – Resolution of the figure.
style (str, default 'default') – Style to use for matplotlib.pyplot. The style is use only in this context and not applied globally.
**kwargs – Additional keyword arguments to be passed to the plt.plot function from matplotlib.
- Returns
Axes returned by the plt.subplots function.
- Return type
plt.axes
Examples
>>> from sklearn.decomposition import PCA >>> pca = PCA(n_components=20) >>> pca.fit(data) >>> plot_pca_explained_variance_ratio(pca)