utils.pca.plot_loading_scores

utils.pca.plot_loading_scores(loading_scores, figsize=(12, 8))

Creates a heatmap visualization of PCA loading scores.

Generates a heatmap showing the relationship between original features and principal components, with color intensity indicating the strength and direction of the relationship.

Parameters

Name Type Description Default
loading_scores pd.DataFrame DataFrame containing the loading scores matrix with features as rows and principal components as columns. required
figsize tuple Size of the figure as (width, height). Defaults to (12, 8). (12, 8)

Returns

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

Example

from sklearn.decomposition import PCA from sklearn.datasets import load_iris from spotpython.utils.pca import print_loading_scores, plot_loading_scores

Load and prepare iris dataset

iris = load_iris() X = iris.data feature_names = iris.feature_names

Fit PCA and get loading scores

pca = PCA() pca.fit(X) scores_df = print_loading_scores(pca, feature_names)

Create heatmap

plot_loading_scores(scores_df, figsize=(10, 6))