Untitled conversation
- User
['ts_id', 'minute', 'CATEGORY', 'DESCRIPTION', 'cat_desc', 'text_chunked', 'text', 'TABLE', 'value', 'feature'] ['ts_id', 'HADM_ID', 'SUBJECT_ID', 'in_hospital_mortality']
the above is my events and oc dataframe respectively. they are loaded from pkls. value and feature are embeddings of type <class 'numpy.ndarray'> while keeping the logic and ensuring compatibility to the original logic as per below, adapt the code for the dfs i have above.
Get train-valid-test split for sup task.
all_sup_subjects = icu.SUBJECT_ID.unique() np.random.seed(0) np.random.shuffle(all_sup_subjects) S = len(all_sup_subjects) bp1, bp2 = int(0.64S), int(0.8S) train_sub = all_sup_subjects[:bp1] valid_sub = all_sup_subjects[bp1:bp2] test_sub = all_sup_subjects[bp2:] icu.rename(columns={'ICUSTAY_ID':'ts_id'}, inplace=True) train_ids = np.array(icu.loc[icu.SUBJECT_ID.isin(train_sub)].ts_id) valid_ids = np.array(icu.loc[icu.SUBJECT_ID.isin(valid_sub)].ts_id) test_ids = np.array(icu.loc[icu.SUBJECT_ID.isin(test_sub)].ts_id)
Filter columns.
events = events[['ts_id', 'minute', 'variable', 'value', 'TABLE']]
Aggregate data.
events['value'] = events['value'].astype(float) events.loc[events['TABLE'].isna(), 'TABLE'] = 'N/A' events = events.groupby(['ts_id', 'minute', 'variable']).agg( {'value':'mean', 'TABLE':'unique'}).reset_index() def f(x): if len(x)==0: return x[0] else: return ','.join(x) events['TABLE'] = events['TABLE'].apply(f)
Save data.
os.makedirs('../data/processed', exist_ok=True) pickle.dump([events, oc, train_ids, valid_ids, test_ids], open('../data/processed/mimic_iii.pkl','wb'))
- Assistant