{"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":"## <div style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Objectives of Notebook 📌</div> ","metadata":{}},{"cell_type":"markdown","source":"<div style=\"border-radius:10px;\n            border :#0A0104 solid;\n            padding: 15px;\n            background-color:  ;\n           font-size:110%;\n            text-align: left\">\n    <center>\n        > 🔍 Example of working with data\n        <br>\n        > ⛏ Create BaseLine model\n        <br>\n    </center>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"1\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Importing Libraries</p>","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom tqdm import tqdm\n\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2023-01-31T11:51:31.368926Z","iopub.execute_input":"2023-01-31T11:51:31.369511Z","iopub.status.idle":"2023-01-31T11:51:32.871774Z","shell.execute_reply.started":"2023-01-31T11:51:31.369390Z","shell.execute_reply":"2023-01-31T11:51:32.870432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"2\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Config</p>","metadata":{}},{"cell_type":"code","source":"class CFG:\n    class data:\n        path_sample_submission = \"/kaggle/input/icecube-neutrinos-in-deep-ice/sample_submission.parquet\"        \n        path_to_sensor_geometry = \"/kaggle/input/icecube-neutrinos-in-deep-ice/sensor_geometry.csv\"\n        path_to_train_meta = \"/kaggle/input/icecube-neutrinos-in-deep-ice/train_meta.parquet\"\n        path_to_test_meta = \"/kaggle/input/icecube-neutrinos-in-deep-ice/test_meta.parquet\"\n        path_to_train_batch = \"/kaggle/input/icecube-neutrinos-in-deep-ice/train\"\n        path_to_test_batch = \"/kaggle/input/icecube-neutrinos-in-deep-ice/test\"","metadata":{"execution":{"iopub.status.busy":"2023-01-31T11:51:32.878432Z","iopub.execute_input":"2023-01-31T11:51:32.879402Z","iopub.status.idle":"2023-01-31T11:51:32.892081Z","shell.execute_reply.started":"2023-01-31T11:51:32.879343Z","shell.execute_reply":"2023-01-31T11:51:32.889405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Loading Dataset</p>","metadata":{}},{"cell_type":"code","source":"sample_meta = pd.read_parquet(CFG.data.path_sample_submission)\n\nsensor_geometry = pd.read_csv(CFG.data.path_to_sensor_geometry)\n\ntrain_meta = pd.read_parquet(CFG.data.path_to_train_meta)\ntest_meta = pd.read_parquet(CFG.data.path_to_test_meta)\n\ntrain_data = pd.concat([pd.read_parquet(f\"{CFG.data.path_to_train_batch}/batch_{i}.parquet\") for i in tqdm(train_meta[\"batch_id\"].unique()[:1])])\ntest_data = pd.concat([pd.read_parquet(f\"{CFG.data.path_to_test_batch}/batch_{i}.parquet\") for i in tqdm(test_meta[\"batch_id\"].unique()[:1])])","metadata":{"execution":{"iopub.status.busy":"2023-01-31T11:51:48.111539Z","iopub.execute_input":"2023-01-31T11:51:48.112110Z","iopub.status.idle":"2023-01-31T11:52:40.868482Z","shell.execute_reply.started":"2023-01-31T11:51:48.112062Z","shell.execute_reply":"2023-01-31T11:52:40.866242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"4\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Extract Features </p>","metadata":{}},{"cell_type":"code","source":"train_data = train_data.merge(sensor_geometry, left_on=\"sensor_id\", right_index=True)\ntrain_features = train_data.groupby(\"event_id\").agg({\"charge\": [\"mean\", \"std\"], \"time\": [\"min\", \"max\"]})\ntrain_features.columns = [\"_\".join(col) for col in train_features.columns]\ntrain_features = train_features.merge(train_meta, left_index=True, right_on=\"event_id\")","metadata":{"execution":{"iopub.status.busy":"2023-01-31T11:52:40.873647Z","iopub.execute_input":"2023-01-31T11:52:40.874816Z","iopub.status.idle":"2023-01-31T11:55:40.050570Z","shell.execute_reply.started":"2023-01-31T11:52:40.874728Z","shell.execute_reply":"2023-01-31T11:55:40.046847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = test_data.merge(sensor_geometry, left_on=\"sensor_id\", right_index=True)\ntest_features = test_data.groupby(\"event_id\").agg({\"charge\": [\"mean\", \"std\"], \"time\": [\"min\", \"max\"]})\ntest_features.columns = [\"_\".join(col) for col in test_features.columns]\ntest_features = test_features.merge(test_meta, left_index=True, right_on=\"event_id\")","metadata":{"execution":{"iopub.status.busy":"2023-01-31T11:55:40.055198Z","iopub.execute_input":"2023-01-31T11:55:40.058275Z","iopub.status.idle":"2023-01-31T11:55:40.081797Z","shell.execute_reply.started":"2023-01-31T11:55:40.058195Z","shell.execute_reply":"2023-01-31T11:55:40.080810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"5\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Split Data</p>","metadata":{}},{"cell_type":"code","source":"train_X, val_X, train_y, val_y = train_test_split(train_features.drop([\"azimuth\", \"zenith\"], axis=1),\n                                                  train_features[[\"azimuth\", \"zenith\"]],\n                                                  test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T11:57:53.495477Z","iopub.execute_input":"2023-01-31T11:57:53.496671Z","iopub.status.idle":"2023-01-31T11:57:53.564891Z","shell.execute_reply.started":"2023-01-31T11:57:53.496579Z","shell.execute_reply":"2023-01-31T11:57:53.563434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"6\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Model & Fit & Predict</p>","metadata":{}},{"cell_type":"code","source":"clf = LinearRegression()\nclf.fit(train_X.values, train_y.values)\n\nval_pred = clf.predict(val_X.values)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T12:24:41.359046Z","iopub.execute_input":"2023-01-31T12:24:41.359567Z","iopub.status.idle":"2023-01-31T12:24:41.644177Z","shell.execute_reply.started":"2023-01-31T12:24:41.359527Z","shell.execute_reply":"2023-01-31T12:24:41.641545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"7\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Get & Save Predict</p>","metadata":{}},{"cell_type":"code","source":"test_pred = clf.predict(test_features.values)\n\npd.DataFrame({\n    \"event_id\": test_features.event_id.values,\n    \"azimuth\": test_pred[:, 0],\n    \"zenith\": test_pred[:, 1],\n}).to_csv('submission.csv', index=False)\n\npd.read_csv(\"submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-31T12:27:57.863779Z","iopub.execute_input":"2023-01-31T12:27:57.864322Z","iopub.status.idle":"2023-01-31T12:27:57.887709Z","shell.execute_reply.started":"2023-01-31T12:27:57.864271Z","shell.execute_reply":"2023-01-31T12:27:57.886436Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3\"></a>\n# <p style=\"padding:10px;background-color:#8000ff;margin:0;color:black;font-family:newtimeroman;font-size:100%;text-align:center;border-radius: 15px 50px;overflow:hidden;font-weight:500\">Thank you for watching!</p>\n\n<center> <img src=\"https://raw.githubusercontent.com/ntclai/PictureForMyProject/main/87481-of-thanks-letter-text-logo-calligraphy-drawing%20(1).png\" style='width: 600px; height: 300px;'>","metadata":{}}]}