From 7112a90dafbfedf487f80b88f776446182d7ba95 Mon Sep 17 00:00:00 2001 From: "houhan@gmail.com" Date: Tue, 3 Dec 2024 22:42:47 +0000 Subject: [PATCH 1/2] fix: remove inf numbers --- code/pages/1_Learning trajectory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/code/pages/1_Learning trajectory.py b/code/pages/1_Learning trajectory.py index 9b598dc..69795a2 100644 --- a/code/pages/1_Learning trajectory.py +++ b/code/pages/1_Learning trajectory.py @@ -47,6 +47,7 @@ def app(): def do_pca(df, name): df = df.dropna(axis=0, how='any') + df = df[~df.isin([np.nan, np.inf, -np.inf]).any(axis=1)] # Standardize the features x = StandardScaler().fit_transform(df.drop(columns=['subject_id', 'session'])) From 4ecbb7219258ecadb5effc2a0cbcf65a4a56af06 Mon Sep 17 00:00:00 2001 From: "houhan@gmail.com" Date: Tue, 3 Dec 2024 23:40:31 +0000 Subject: [PATCH 2/2] fix: task columns --- code/pages/1_Learning trajectory.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/code/pages/1_Learning trajectory.py b/code/pages/1_Learning trajectory.py index 69795a2..d8fa143 100644 --- a/code/pages/1_Learning trajectory.py +++ b/code/pages/1_Learning trajectory.py @@ -32,7 +32,7 @@ def app(): # -- get cols -- col_task = [s for s in df.metadata.columns if not any(ss in s for ss in ['lickspout', 'weight', 'water', 'time', 'rig', - 'user_name', 'experiment', 'task', 'notes'] + 'user_name', 'experiment', 'task', 'notes', 'laser'] ) ] @@ -47,10 +47,13 @@ def app(): def do_pca(df, name): df = df.dropna(axis=0, how='any') - df = df[~df.isin([np.nan, np.inf, -np.inf]).any(axis=1)] + df = df[~df.isin([np.nan, np.inf, -np.inf]).any(axis=1)] + + df_to_pca = df.drop(columns=['subject_id', 'session']) + df_to_pca = df_to_pca.select_dtypes(include=[np.number, float, int]) # Standardize the features - x = StandardScaler().fit_transform(df.drop(columns=['subject_id', 'session'])) + x = StandardScaler().fit_transform(df_to_pca) # Apply PCA pca = PCA(n_components=10) # Reduce to 2 dimensions for visualization @@ -63,6 +66,7 @@ def do_pca(df, name): principalDf.reset_index(inplace=True) # -- trajectory -- + st.markdown(f'### PCA on {name} metrics') fig = go.Figure() for mouse_id in principalDf['subject_id'].unique(): @@ -109,7 +113,7 @@ def do_pca(df, name): # -- pca components -- pca_components = pd.DataFrame(pca.components_, - columns=df.drop(columns=['subject_id', 'session']).columns) + columns=df_to_pca.columns) pca_components fig = make_subplots(rows=3, cols=1)