{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import StratifiedKFold","metadata":{"execution":{"iopub.status.busy":"2021-09-17T10:17:02.984560Z","iopub.execute_input":"2021-09-17T10:17:02.985032Z","iopub.status.idle":"2021-09-17T10:17:03.878138Z","shell.execute_reply.started":"2021-09-17T10:17:02.984900Z","shell.execute_reply":"2021-09-17T10:17:03.876993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train_labels.csv')\n# Exclusion of three cases from training cohort\n# https://www.kaggle.com/c/rsna-miccai-brain-tumor-radiogenomic-classification/discussion/262046\ndf = df[~df['BraTS21ID'].isin([109, 123, 709])]\ndf = df.sort_values(by='BraTS21ID')\ndf = df.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2021-09-17T10:17:03.880021Z","iopub.execute_input":"2021-09-17T10:17:03.880289Z","iopub.status.idle":"2021-09-17T10:17:03.907215Z","shell.execute_reply.started":"2021-09-17T10:17:03.880259Z","shell.execute_reply":"2021-09-17T10:17:03.906187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cv = StratifiedKFold(n_splits=3, random_state=42, shuffle=True)\nX, y = df['BraTS21ID'].values, df['MGMT_value'].values\n\nfor i, (train_idx, val_idx) in enumerate(cv.split(X, y)):\n    df.loc[val_idx, 'fold'] = i\ndf['fold'] = df['fold'].astype(int)","metadata":{"execution":{"iopub.status.busy":"2021-09-17T10:17:03.908529Z","iopub.execute_input":"2021-09-17T10:17:03.908784Z","iopub.status.idle":"2021-09-17T10:17:03.926330Z","shell.execute_reply.started":"2021-09-17T10:17:03.908756Z","shell.execute_reply":"2021-09-17T10:17:03.925363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('split.csv', index=False)\ndf.head(20)","metadata":{"execution":{"iopub.status.busy":"2021-09-17T10:17:03.928069Z","iopub.execute_input":"2021-09-17T10:17:03.928319Z","iopub.status.idle":"2021-09-17T10:17:03.949854Z","shell.execute_reply.started":"2021-09-17T10:17:03.928288Z","shell.execute_reply":"2021-09-17T10:17:03.949237Z"},"trusted":true},"execution_count":null,"outputs":[]}]}