|
|
import pandas as pd |
|
|
import xlsxwriter |
|
|
from sklearn.model_selection import train_test_split |
|
|
|
|
|
|
|
|
file_path = '/Users/colestephens/Desktop/CodeFolders/ML_Dataset_Curation_Project/Sanitized_data/homo_hydrogenation.csv' |
|
|
df = pd.read_csv(file_path) |
|
|
|
|
|
|
|
|
n_splits = 5 |
|
|
|
|
|
|
|
|
output_file = '/Users/colestephens/Desktop/CodeFolders/ML_Dataset_Curation_Project/Split_data/homo_hydrogenation.xlsx' |
|
|
|
|
|
with pd.ExcelWriter(output_file, engine='xlsxwriter') as writer: |
|
|
for split_index in range(n_splits): |
|
|
|
|
|
train_df, test_df = train_test_split(df, test_size=0.2, random_state=split_index) |
|
|
|
|
|
|
|
|
train_sheet_name = f'train_split_{split_index}' |
|
|
test_sheet_name = f'test_split_{split_index}' |
|
|
|
|
|
train_df.to_excel(writer, sheet_name=train_sheet_name, index=False) |
|
|
test_df.to_excel(writer, sheet_name=test_sheet_name, index=False) |
|
|
|
|
|
print(f'Train-test splits saved to {output_file}') |