{"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":"from pathlib import Path\nimport numpy as np\nimport pandas as pd\nimport copy\nimport plotly.express as px\nimport plotly.graph_objects as go\nimport pyproj\nimport json\nimport bisect\n\nimport matplotlib.pyplot as plt\nfrom matplotlib.collections import LineCollection\nfrom matplotlib.colors import ListedColormap, BoundaryNorm\n\nimport warnings\nwarnings.simplefilter('ignore')\npd.set_option('display.max_rows',10)\npd.set_option('display.max_columns',None)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-05-18T15:06:59.540568Z","iopub.execute_input":"2022-05-18T15:06:59.54101Z","iopub.status.idle":"2022-05-18T15:07:01.464467Z","shell.execute_reply.started":"2022-05-18T15:06:59.540901Z","shell.execute_reply":"2022-05-18T15:07:01.463237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def visualize_trafic(df, center={\"lat\":37.5, \"lon\":-122.1}, zoom=9):\n    fig = px.scatter_mapbox(df,\n                            \n                            # Here, plotly gets, (x,y) coordinates\n                            lat=\"LatitudeDegrees\",\n                            lon=\"LongitudeDegrees\",\n                            \n                            #Here, plotly detects color of series\n                            color=\"tripId\",\n                            labels=\"tripId\",\n                            \n                            zoom=zoom,\n                            center=center,\n                            height=500,\n                            width=1000)\n    fig.update_layout(mapbox_style='stamen-terrain')\n    fig.update_layout(margin={\"r\": 0, \"t\": 0, \"l\": 0, \"b\": 0})\n    fig.update_layout(title_text=\"GPS trafic\")\n    fig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-05-18T15:07:01.467556Z","iopub.execute_input":"2022-05-18T15:07:01.467979Z","iopub.status.idle":"2022-05-18T15:07:01.478559Z","shell.execute_reply.started":"2022-05-18T15:07:01.467917Z","shell.execute_reply":"2022-05-18T15:07:01.477578Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# https://www.kaggle.com/code/saitodevel01/gsdc2-baseline-submission\ndf_sub = pd.read_csv('../input/gsdc2-baseline-submission/submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:01.479912Z","iopub.execute_input":"2022-05-18T15:07:01.480781Z","iopub.status.idle":"2022-05-18T15:07:01.686738Z","shell.execute_reply.started":"2022-05-18T15:07:01.480741Z","shell.execute_reply":"2022-05-18T15:07:01.685667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:01.689787Z","iopub.execute_input":"2022-05-18T15:07:01.690764Z","iopub.status.idle":"2022-05-18T15:07:01.716677Z","shell.execute_reply.started":"2022-05-18T15:07:01.690703Z","shell.execute_reply":"2022-05-18T15:07:01.715348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"public_trips = [\n    '2021-06-22-US-MTV-1/XiaomiMi8',\n    '2021-08-12-US-MTV-1/GooglePixel4',\n    '2021-08-17-US-MTV-1/GooglePixel5',\n    '2021-08-24-US-SVL-2/GooglePixel5',\n    '2021-09-07-US-MTV-1/SamsungGalaxyS20Ultra',\n    '2021-09-14-US-MTV-1/GooglePixel5',\n    '2021-09-20-US-MTV-1/XiaomiMi8',\n    '2021-09-20-US-MTV-2/GooglePixel4',\n    '2022-01-04-US-MTV-1/SamsungGalaxyS20Ultra',\n    '2022-01-11-US-MTV-1/GooglePixel6Pro',\n    '2022-01-26-US-MTV-1/XiaomiMi8',\n    '2022-02-01-US-SJC-1/XiaomiMi8',\n    '2022-02-08-US-SJC-1/XiaomiMi8',\n    '2022-02-15-US-SJC-1/GooglePixel5',\n    '2022-02-23-US-LAX-1/GooglePixel5',\n    '2022-02-23-US-LAX-3/XiaomiMi8',\n    '2022-02-23-US-LAX-5/XiaomiMi8',\n    '2022-02-24-US-LAX-1/SamsungGalaxyS20Ultra',\n    '2022-02-24-US-LAX-3/XiaomiMi8',\n    '2022-02-24-US-LAX-5/SamsungGalaxyS20Ultra',\n    '2022-03-14-US-MTV-1/GooglePixel5',\n    '2022-03-17-US-SJC-1/GooglePixel5',\n    '2022-03-31-US-LAX-3/SamsungGalaxyS20Ultra',\n    '2022-04-01-US-LAX-1/SamsungGalaxyS20Ultra',\n    '2022-04-01-US-LAX-3/XiaomiMi8',\n    '2022-04-22-US-OAK-1/GooglePixel5',\n    '2022-04-22-US-OAK-2/XiaomiMi8',\n    '2022-04-25-US-OAK-2/GooglePixel4'\n]\n\nprivate_trips = [\n    '2021-04-28-US-MTV-2/SamsungGalaxyS20Ultra',\n    '2021-09-28-US-MTV-1/GooglePixel5',\n    '2021-11-05-US-MTV-1/XiaomiMi8',\n    '2021-11-30-US-MTV-1/GooglePixel5',\n    '2022-01-18-US-SJC-2/GooglePixel5',\n    '2022-03-22-US-MTV-1/SamsungGalaxyS20Ultra',\n    '2022-03-31-US-LAX-1/GooglePixel5',\n    '2022-04-25-US-OAK-1/GooglePixel5',\n]","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:01.718101Z","iopub.execute_input":"2022-05-18T15:07:01.718884Z","iopub.status.idle":"2022-05-18T15:07:01.725699Z","shell.execute_reply.started":"2022-05-18T15:07:01.718842Z","shell.execute_reply":"2022-05-18T15:07:01.724925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_public = df_sub[df_sub['tripId'].isin(public_trips)].reset_index(drop = True)\ndf_private = df_sub[df_sub['tripId'].isin(private_trips)].reset_index(drop = True)","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:01.727011Z","iopub.execute_input":"2022-05-18T15:07:01.727414Z","iopub.status.idle":"2022-05-18T15:07:01.770957Z","shell.execute_reply.started":"2022-05-18T15:07:01.727367Z","shell.execute_reply":"2022-05-18T15:07:01.77021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check private ratio\n# This leaderboard is calculated with approximately 80% of the test data. The final results will be based on the other 20%, so the final standings may be different.\n\nprint('public ratio :',round(len(df_public)/len(df_sub),3))\nprint('private ratio :',round(len(df_private)/len(df_sub),3))","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:01.772264Z","iopub.execute_input":"2022-05-18T15:07:01.772988Z","iopub.status.idle":"2022-05-18T15:07:01.780868Z","shell.execute_reply.started":"2022-05-18T15:07:01.772943Z","shell.execute_reply":"2022-05-18T15:07:01.779872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualize Public Trip","metadata":{}},{"cell_type":"code","source":"visualize_trafic(df_public)","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:01.782552Z","iopub.execute_input":"2022-05-18T15:07:01.782968Z","iopub.status.idle":"2022-05-18T15:07:03.254642Z","shell.execute_reply.started":"2022-05-18T15:07:01.782933Z","shell.execute_reply":"2022-05-18T15:07:03.253446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Visualize Private Trip","metadata":{}},{"cell_type":"code","source":"visualize_trafic(df_private)","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:03.256605Z","iopub.execute_input":"2022-05-18T15:07:03.257304Z","iopub.status.idle":"2022-05-18T15:07:03.377826Z","shell.execute_reply.started":"2022-05-18T15:07:03.25727Z","shell.execute_reply":"2022-05-18T15:07:03.376951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Make override submission","metadata":{}},{"cell_type":"code","source":"def override_lad(df,tripId):\n    df_override = df.copy()\n    df_override.loc[df_override['tripId'] == tripId,'LatitudeDegrees'] = 0\n    return df_override","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:03.379877Z","iopub.execute_input":"2022-05-18T15:07:03.380106Z","iopub.status.idle":"2022-05-18T15:07:03.38493Z","shell.execute_reply.started":"2022-05-18T15:07:03.380078Z","shell.execute_reply":"2022-05-18T15:07:03.38408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub_override = df_sub.copy()\n\nfor tripId in private_trips:\n    df_sub_override = override_lad(df_sub_override,tripId)\n    print(f'override:{tripId}')","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:03.386299Z","iopub.execute_input":"2022-05-18T15:07:03.386532Z","iopub.status.idle":"2022-05-18T15:07:03.503556Z","shell.execute_reply.started":"2022-05-18T15:07:03.386503Z","shell.execute_reply":"2022-05-18T15:07:03.502345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub_override.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:03.504773Z","iopub.execute_input":"2022-05-18T15:07:03.505019Z","iopub.status.idle":"2022-05-18T15:07:03.517646Z","shell.execute_reply.started":"2022-05-18T15:07:03.504989Z","shell.execute_reply":"2022-05-18T15:07:03.516406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Submit override prediction and check LB.","metadata":{}},{"cell_type":"code","source":"df_sub_override.to_csv('df_sub_override',index = False)","metadata":{"execution":{"iopub.status.busy":"2022-05-18T15:07:03.519202Z","iopub.execute_input":"2022-05-18T15:07:03.519462Z","iopub.status.idle":"2022-05-18T15:07:03.986042Z","shell.execute_reply.started":"2022-05-18T15:07:03.519431Z","shell.execute_reply":"2022-05-18T15:07:03.984832Z"},"trusted":true},"execution_count":null,"outputs":[]}]}