PCA Loadings (2D)ΒΆ

This example will plot PCA loadings along two principal axes.

  • plot 011 2d loadings
  • plot 011 2d loadings
from matplotlib import pyplot as plt
import pandas as pd
from sklearn.datasets import load_diabetes
from sklearn.preprocessing import scale
from sklearn.decomposition import PCA
from psynlig import pca_2d_loadings
plt.style.use('seaborn-talk')

data_set = load_diabetes()
data = pd.DataFrame(data_set['data'], columns=data_set['feature_names'])
data = scale(data)

pca = PCA()
pca.fit_transform(data)

text_settings = {
    'fontsize': 'xx-large',
    'outline': {'foreground': '0.2'}
}

pca_2d_loadings(
    pca,
    data_set['feature_names'],
    select_components={(3, 4)},
    text_settings=text_settings
)

# Remove text in plot and add legend:
_, axes = pca_2d_loadings(
    pca,
    data_set['feature_names'],
    select_components={(3, 4)},
    text_settings={'show': False},
)

for axi in axes:
    axi.legend()

plt.show()

Total running time of the script: ( 0 minutes 0.750 seconds)

Gallery generated by Sphinx-Gallery