{"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 os \nimport glob\n\nimport pandas as pd\nimport numpy as np\nimport pyarrow.parquet as pq\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px\n\nimport time\n\nimport xgboost\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-24T11:44:17.603127Z","iopub.execute_input":"2023-01-24T11:44:17.603539Z","iopub.status.idle":"2023-01-24T11:44:17.609930Z","shell.execute_reply.started":"2023-01-24T11:44:17.603487Z","shell.execute_reply":"2023-01-24T11:44:17.608809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pyarrow.parquet import ParquetFile\nimport pyarrow as pa \n\npf = ParquetFile('/kaggle/input/icecube-neutrinos-in-deep-ice/train_meta.parquet') \nfirst_ten_rows = next(pf.iter_batches(batch_size = 500000)) \ndf = pa.Table.from_batches([first_ten_rows]).to_pandas() \n\nsensor = pd.read_csv(\"/kaggle/input/icecube-neutrinos-in-deep-ice/sensor_geometry.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:44:17.612017Z","iopub.execute_input":"2023-01-24T11:44:17.612694Z","iopub.status.idle":"2023-01-24T11:44:18.787049Z","shell.execute_reply.started":"2023-01-24T11:44:17.612658Z","shell.execute_reply":"2023-01-24T11:44:18.786124Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:44:18.789129Z","iopub.execute_input":"2023-01-24T11:44:18.789744Z","iopub.status.idle":"2023-01-24T11:44:18.803230Z","shell.execute_reply.started":"2023-01-24T11:44:18.789686Z","shell.execute_reply":"2023-01-24T11:44:18.802179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sensor.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:44:18.805059Z","iopub.execute_input":"2023-01-24T11:44:18.805354Z","iopub.status.idle":"2023-01-24T11:44:18.819178Z","shell.execute_reply.started":"2023-01-24T11:44:18.805329Z","shell.execute_reply":"2023-01-24T11:44:18.817956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sensor = pd.read_csv('/kaggle/input/icecube-neutrinos-in-deep-ice/sensor_geometry.csv')\nfig = px.scatter_3d( sensor, template=\"plotly_dark\", x='x', y='y', z='z', color='sensor_id', size='sensor_id',\n                   title=\"IceCube Observatory\")\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:44:18.821715Z","iopub.execute_input":"2023-01-24T11:44:18.822137Z","iopub.status.idle":"2023-01-24T11:44:18.901713Z","shell.execute_reply.started":"2023-01-24T11:44:18.822104Z","shell.execute_reply":"2023-01-24T11:44:18.900769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df[['first_pulse_index','last_pulse_index']]\ny = df[['azimuth','zenith']]\n\nmodel = xgboost.XGBRegressor(n_estimators=1000, max_depth=7, eta=0.1, subsample=0.7, colsample_bytree=0.8)\n\nx_train, x_test, y_train, y_test = train_test_split(x,y, test_size=0.2)\nmodel.fit(x_train, y_train)\npred = model.predict(x_test)\n\nprint(\"Mean Squared Error (Azimuth):\", mean_squared_error(y_test[\"azimuth\"], pred[:,0]))\nprint(\"Mean Squared Error (Zenith):\", mean_squared_error(y_test[\"zenith\"], pred[:,1]))","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:44:19.289210Z","iopub.execute_input":"2023-01-24T11:44:19.290118Z","iopub.status.idle":"2023-01-24T11:50:45.907404Z","shell.execute_reply.started":"2023-01-24T11:44:19.290078Z","shell.execute_reply":"2023-01-24T11:50:45.906661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pq.read_pandas('/kaggle/input/icecube-neutrinos-in-deep-ice/test_meta.parquet').to_pandas()","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:50:45.910666Z","iopub.execute_input":"2023-01-24T11:50:45.912687Z","iopub.status.idle":"2023-01-24T11:50:45.934613Z","shell.execute_reply.started":"2023-01-24T11:50:45.912656Z","shell.execute_reply":"2023-01-24T11:50:45.933735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:50:45.935896Z","iopub.execute_input":"2023-01-24T11:50:45.936517Z","iopub.status.idle":"2023-01-24T11:50:45.947521Z","shell.execute_reply.started":"2023-01-24T11:50:45.936474Z","shell.execute_reply":"2023-01-24T11:50:45.946446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(test[['first_pulse_index','last_pulse_index']])\nsub = pd.DataFrame({'event_id':test.index,'azimuth':pred[:,0],'zenith':pred[:,1]})\nsub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-01-24T11:50:45.950124Z","iopub.execute_input":"2023-01-24T11:50:45.950373Z","iopub.status.idle":"2023-01-24T11:50:45.963514Z","shell.execute_reply.started":"2023-01-24T11:50:45.950350Z","shell.execute_reply":"2023-01-24T11:50:45.962551Z"},"trusted":true},"execution_count":null,"outputs":[]}]}