Skip to content

Commit 4ecbb72

Browse files
committed
fix: task columns
1 parent 7112a90 commit 4ecbb72

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

code/pages/1_Learning trajectory.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def app():
3232
# -- get cols --
3333
col_task = [s for s in df.metadata.columns
3434
if not any(ss in s for ss in ['lickspout', 'weight', 'water', 'time', 'rig',
35-
'user_name', 'experiment', 'task', 'notes']
35+
'user_name', 'experiment', 'task', 'notes', 'laser']
3636
)
3737
]
3838

@@ -47,10 +47,13 @@ def app():
4747

4848
def do_pca(df, name):
4949
df = df.dropna(axis=0, how='any')
50-
df = df[~df.isin([np.nan, np.inf, -np.inf]).any(axis=1)]
50+
df = df[~df.isin([np.nan, np.inf, -np.inf]).any(axis=1)]
51+
52+
df_to_pca = df.drop(columns=['subject_id', 'session'])
53+
df_to_pca = df_to_pca.select_dtypes(include=[np.number, float, int])
5154

5255
# Standardize the features
53-
x = StandardScaler().fit_transform(df.drop(columns=['subject_id', 'session']))
56+
x = StandardScaler().fit_transform(df_to_pca)
5457

5558
# Apply PCA
5659
pca = PCA(n_components=10) # Reduce to 2 dimensions for visualization
@@ -63,6 +66,7 @@ def do_pca(df, name):
6366
principalDf.reset_index(inplace=True)
6467

6568
# -- trajectory --
69+
st.markdown(f'### PCA on {name} metrics')
6670
fig = go.Figure()
6771

6872
for mouse_id in principalDf['subject_id'].unique():
@@ -109,7 +113,7 @@ def do_pca(df, name):
109113

110114
# -- pca components --
111115
pca_components = pd.DataFrame(pca.components_,
112-
columns=df.drop(columns=['subject_id', 'session']).columns)
116+
columns=df_to_pca.columns)
113117
pca_components
114118
fig = make_subplots(rows=3, cols=1)
115119

0 commit comments

Comments
 (0)