Skip to content

Instantly share code, notes, and snippets.

@Arafat245
Created May 20, 2025 12:01
Show Gist options
  • Select an option

  • Save Arafat245/2e30fc6ee33ffab68df441715d80110a to your computer and use it in GitHub Desktop.

Select an option

Save Arafat245/2e30fc6ee33ffab68df441715d80110a to your computer and use it in GitHub Desktop.
Train_Test_fold_loop
df = pd.read_excel(r"C:\Rhythm\test_ds_loc.xlsx")
unique_subjects = df['p_id'].unique()
for subject in unique_subjects:
test_subject_df = df[df['p_id'] == subject].sort_values(by='date')
train_df = df[df['p_id'] != subject]
n = len(test_subject_df)
if n < 3:
continue
split1 = n // 3
split2 = 2 * n // 3
test_fold = test_subject_df.iloc[split2:]
pseudo_train_fold = test_subject_df.iloc[:split2]
final_train_df = pd.concat([train_df, pseudo_train_fold], ignore_index=True)
td = final_train_df[final_train_df['p_id'] == subject]
print(f"Subject: {subject} | last Train Date: {td['date'].max()} | 1st Test Date: {test_fold['date'].min()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment