utils.pca.plot_pca_scree

utils.pca.plot_pca_scree(pca, df_name='', max_scree=None, figsize=(12, 6))

Plot the scree plot for Principal Component Analysis (PCA).

A scree plot shows the percentage of variance explained by each principal component in descending order. It helps in determining the optimal number of components to retain.

Parameters

Name Type Description Default
pca sklearn.decomposition.PCA Fitted PCA object containing the explained variance ratios. required
df_name str Name of the dataset to be displayed in the plot title. Defaults to empty string. ''
max_scree int Maximum number of principal components to plot. If None, all components are plotted. Defaults to None. None
figsize tuple Size of the figure as (width, height). Defaults to (12, 6). (12, 6)

Returns

Name Type Description
None None The function creates and displays a matplotlib plot.

Examples

>>> import numpy as np
>>> from sklearn.decomposition import PCA
>>> from sklearn.datasets import load_iris
>>> from spotpython.utils.pca import plot_pca_scree
>>>
>>> # Load iris dataset
>>> iris = load_iris()
>>> X = iris.data
>>>
>>> # Fit PCA
>>> pca = PCA()
>>> pca.fit(X)
>>>
>>> # Create scree plot
>>> plot_pca_scree(pca,
...                df_name="Iris Dataset",
...                max_scree=4,
...                figsize=(10, 5))