@@ -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,9 +47,13 @@ def app():
4747
4848def 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 )]
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 ])
5054
5155 # Standardize the features
52- x = StandardScaler ().fit_transform (df . drop ( columns = [ 'subject_id' , 'session' ]) )
56+ x = StandardScaler ().fit_transform (df_to_pca )
5357
5458 # Apply PCA
5559 pca = PCA (n_components = 10 ) # Reduce to 2 dimensions for visualization
@@ -62,6 +66,7 @@ def do_pca(df, name):
6266 principalDf .reset_index (inplace = True )
6367
6468 # -- trajectory --
69+ st .markdown (f'### PCA on { name } metrics' )
6570 fig = go .Figure ()
6671
6772 for mouse_id in principalDf ['subject_id' ].unique ():
@@ -108,7 +113,7 @@ def do_pca(df, name):
108113
109114 # -- pca components --
110115 pca_components = pd .DataFrame (pca .components_ ,
111- columns = df . drop ( columns = [ 'subject_id' , 'session' ]) .columns )
116+ columns = df_to_pca .columns )
112117 pca_components
113118 fig = make_subplots (rows = 3 , cols = 1 )
114119
0 commit comments