Created
July 7, 2022 20:26
-
-
Save erichare/d468b8b72d70e008b4a702e9776b25c0 to your computer and use it in GitHub Desktop.
Fit a PCA using scikit-learn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fit_pca(pca_data, x_component=1, y_component=2, split_by=None): | |
... | |
pca_df = df[vars] | |
pca = PCA(n_components=n_components) | |
pca.fit(pca_df) | |
... | |
pca_data = pd.DataFrame(pca.fit_transform(pca_df)) | |
return pca_data | |
def plot_pca(pca_data, x_component=1, y_component=2, split_by=None): | |
fig = figure(plot_width=1000, plot_height=1000) | |
for pop in pca_data["split"].unique().tolist(): | |
... | |
return fig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment