Download Scripts/Test_train_split.py from Coleste/BIOINF595_Final: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/datasets/Coleste/BIOINF595_Final/resolve/main/Scripts/Test_train_split.py
- Command line
-
hf download hf://datasets/Coleste/BIOINF595_Final/Scripts/Test_train_split.py
-
curl -L -o Test_train_split.py https://huggingface.co/datasets/Coleste/BIOINF595_Final/resolve/main/Scripts/Test_train_split.py
1.13 kB
| import pandas as pd | |
| import xlsxwriter | |
| from sklearn.model_selection import train_test_split | |
| # Load your prepared dataset | |
| file_path = '/Users/colestephens/Desktop/CodeFolders/ML_Dataset_Curation_Project/Sanitized_data/homo_hydrogenation.csv' # Path to your sanitized CSV | |
| df = pd.read_csv(file_path) | |
| # Number of splits you want to create | |
| n_splits = 5 | |
| # Initialize a writer to write multiple sheets | |
| 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): | |
| # Perform the train-test split | |
| train_df, test_df = train_test_split(df, test_size=0.2, random_state=split_index) | |
| # Write each train and test split to separate sheets | |
| 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}') |