{"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 numpy as np\nimport pandas as pd \nfrom sklearn.model_selection import StratifiedKFold","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-15T01:59:51.274454Z","iopub.execute_input":"2021-11-15T01:59:51.276270Z","iopub.status.idle":"2021-11-15T01:59:51.281094Z","shell.execute_reply.started":"2021-11-15T01:59:51.276173Z","shell.execute_reply":"2021-11-15T01:59:51.280297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# load training data ","metadata":{}},{"cell_type":"code","source":"training_labels = pd.read_csv(\"../input/g2net-gravitational-wave-detection/training_labels.csv\")\ntraining_labels.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-15T01:59:51.282841Z","iopub.execute_input":"2021-11-15T01:59:51.283374Z","iopub.status.idle":"2021-11-15T01:59:51.697230Z","shell.execute_reply.started":"2021-11-15T01:59:51.283336Z","shell.execute_reply":"2021-11-15T01:59:51.696132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# get unique label count ","metadata":{}},{"cell_type":"code","source":"training_labels.target.nunique()","metadata":{"execution":{"iopub.status.busy":"2021-11-15T01:59:51.699018Z","iopub.execute_input":"2021-11-15T01:59:51.699622Z","iopub.status.idle":"2021-11-15T01:59:51.709786Z","shell.execute_reply.started":"2021-11-15T01:59:51.699570Z","shell.execute_reply":"2021-11-15T01:59:51.709223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# split folds for 5 fold training model","metadata":{}},{"cell_type":"code","source":"skf = StratifiedKFold(n_splits=5,random_state=42, shuffle=True)\nskfSplit = skf.split(training_labels, training_labels[\"target\"])\nfold = 1\nfor train_index, test_index in skfSplit:\n    training_labels.loc[test_index,\"fold\"] = fold\n    fold = fold + 1\n    print(\"TRAIN:\", train_index, \"TEST:\", test_index)\n    \ntraining_labels = training_labels.astype({'fold': 'int64'})\n\nprint(training_labels.info())\ntraining_labels.to_csv(\"g2net_5folds.csv\",index = False)\n    \ntraining_labels.head(20)","metadata":{"execution":{"iopub.status.busy":"2021-11-15T01:59:51.711223Z","iopub.execute_input":"2021-11-15T01:59:51.711702Z","iopub.status.idle":"2021-11-15T01:59:53.264287Z","shell.execute_reply.started":"2021-11-15T01:59:51.711667Z","shell.execute_reply":"2021-11-15T01:59:53.263390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = pd.read_csv(\"./g2net_5folds.csv\")\nresult.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-15T01:59:53.267135Z","iopub.execute_input":"2021-11-15T01:59:53.267763Z","iopub.status.idle":"2021-11-15T01:59:53.727610Z","shell.execute_reply.started":"2021-11-15T01:59:53.267699Z","shell.execute_reply":"2021-11-15T01:59:53.726608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# split folds for 10 fold training model","metadata":{}},{"cell_type":"code","source":"skf = StratifiedKFold(n_splits=10,random_state=42, shuffle=True)\nskfSplit = skf.split(training_labels, training_labels[\"target\"])\nfold = 1\nfor train_index, test_index in skfSplit:\n    training_labels.loc[test_index,\"fold\"] = fold\n    fold = fold + 1\n    print(\"TRAIN:\", train_index, \"TEST:\", test_index)\n    \ntraining_labels = training_labels.astype({'fold': 'int64'})\n\nprint(training_labels.info())\ntraining_labels.to_csv(\"g2net_10folds.csv\",index = False)\n    \ntraining_labels.head(20)","metadata":{"execution":{"iopub.status.busy":"2021-11-15T01:59:53.729318Z","iopub.execute_input":"2021-11-15T01:59:53.729572Z","iopub.status.idle":"2021-11-15T01:59:55.332092Z","shell.execute_reply.started":"2021-11-15T01:59:53.729541Z","shell.execute_reply":"2021-11-15T01:59:55.330965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = pd.read_csv(\"./g2net_10folds.csv\")\nresult.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-15T01:59:55.333818Z","iopub.execute_input":"2021-11-15T01:59:55.334067Z","iopub.status.idle":"2021-11-15T01:59:55.810332Z","shell.execute_reply.started":"2021-11-15T01:59:55.334037Z","shell.execute_reply":"2021-11-15T01:59:55.809253Z"},"trusted":true},"execution_count":null,"outputs":[]}]}