njab.sklearn.pca module#
- njab.sklearn.pca.plot_explained_variance(pca: PCA, ax: Axes | None = None) Axes [source]#
Plot explained variance of PCA from scikit-learn.
- njab.sklearn.pca.run_pca(df_wide: DataFrame, n_components: int = 2) tuple[DataFrame, PCA] [source]#
Run PCA on DataFrame and return result.
- Parameters:
df (pd.DataFrame) – DataFrame in wide format to fit features on.
n_components (int, optional) – Number of Principal Components to fit, by default 2
- Returns:
principal compoments of DataFrame with same indices as in original DataFrame, and fitted PCA model of sklearn
- Return type:
Tuple[pd.DataFrame, PCA]