Skip to content

Commit

Permalink
🐛 make decomposition a module
Browse files Browse the repository at this point in the history
  • Loading branch information
enryH committed Nov 25, 2024
1 parent 0b3cd6e commit 545299b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions acore/decomposition/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pca

__all__ = ["pca"]
6 changes: 3 additions & 3 deletions acore/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def run_pca(
n_comp_max = min(df_wide.shape)
n_comp_max = min(n_comp_max, n_components)
pca = sklearn.decomposition.PCA(n_components=n_comp_max)
PCs = pca.fit_transform(df_wide)
pcs = pca.fit_transform(df_wide)
cols = [
f"principal component {i+1} ({var_explained*100:.2f} %)"
for i, var_explained in enumerate(pca.explained_variance_ratio_)
]
PCs = pd.DataFrame(PCs, index=df_wide.index, columns=cols)
return PCs, pca
pcs = pd.DataFrame(pcs, index=df_wide.index, columns=cols)
return pcs, pca

0 comments on commit 545299b

Please sign in to comment.