{"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":"markdown","source":"### 1. ABOUT THE COMPETITION","metadata":{}},{"cell_type":"markdown","source":"In this competition you are provided with a training set of time series data containing simulated gravitational wave measurements from a network of 3 gravitational wave interferometers (LIGO Hanford, LIGO Livingston, and Virgo). Each time series contains either detector noise or detector noise plus a simulated gravitational wave signal. The task is to identify when a signal is present in the data (target=1).","metadata":{}},{"cell_type":"code","source":"import os\nimport json\nimport random\nimport collections\n\nimport numpy as np\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom sklearn.metrics import roc_auc_score, roc_curve, auc","metadata":{"execution":{"iopub.status.busy":"2021-06-30T18:03:40.555546Z","iopub.execute_input":"2021-06-30T18:03:40.556207Z","iopub.status.idle":"2021-06-30T18:03:42.098009Z","shell.execute_reply.started":"2021-06-30T18:03:40.556089Z","shell.execute_reply":"2021-06-30T18:03:42.097086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2.DATA VISUALIZATION","metadata":{}},{"cell_type":"code","source":"def convert_image_id_2_path(image_id: str, is_train: bool = True) -> str:\n    folder = \"train\" if is_train else \"test\"\n    return \"../input/g2net-gravitational-wave-detection/{}/{}/{}/{}/{}.npy\".format(\n        folder, image_id[0], image_id[1], image_id[2], image_id \n    )","metadata":{"execution":{"iopub.status.busy":"2021-06-30T18:04:00.642465Z","iopub.execute_input":"2021-06-30T18:04:00.643042Z","iopub.status.idle":"2021-06-30T18:04:00.647932Z","shell.execute_reply.started":"2021-06-30T18:04:00.642994Z","shell.execute_reply":"2021-06-30T18:04:00.64708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"../input/g2net-gravitational-wave-detection/training_labels.csv\")\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2021-06-30T18:04:03.281936Z","iopub.execute_input":"2021-06-30T18:04:03.282696Z","iopub.status.idle":"2021-06-30T18:04:03.766461Z","shell.execute_reply.started":"2021-06-30T18:04:03.282626Z","shell.execute_reply":"2021-06-30T18:04:03.765594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_y_true = [\n    [1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.],\n    [1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.],\n    [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.], #  IMBALANCE\n]\nlist_y_pred = [\n    [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],\n    [0.9, 0.9, 0.9, 0.9, 0.1, 0.9, 0.9, 0.1, 0.9, 0.1, 0.1, 0.5],\n    [1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], #  IMBALANCE\n]\n\nfor y_true, y_pred in zip(list_y_true, list_y_pred):\n    fpr, tpr, _ = roc_curve(y_true, y_pred)\n    roc_auc = auc(fpr, tpr)\n\n    plt.figure(figsize=(5, 5))\n    plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve (area = %0.2f)' % roc_auc)\n    plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')\n    plt.xlim([-0.01, 1.0])\n    plt.ylim([0.0, 1.05])\n    plt.xlabel('False Positive Rate')\n    plt.ylabel('True Positive Rate')\n    plt.title('Receiver operating characteristic example')\n    plt.legend(loc=\"lower right\")\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-30T18:04:08.394379Z","iopub.execute_input":"2021-06-30T18:04:08.39477Z","iopub.status.idle":"2021-06-30T18:04:08.94006Z","shell.execute_reply.started":"2021-06-30T18:04:08.394737Z","shell.execute_reply":"2021-06-30T18:04:08.939165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv(\"../input/g2net-gravitational-wave-detection/sample_submission.csv\")\nsubmission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2021-06-30T18:04:31.931543Z","iopub.execute_input":"2021-06-30T18:04:31.93194Z","iopub.status.idle":"2021-06-30T18:04:32.764959Z","shell.execute_reply.started":"2021-06-30T18:04:31.931904Z","shell.execute_reply":"2021-06-30T18:04:32.763993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}