{"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":"In this notebook, test trips are divided into public & pribvate and visualized.  \n\nbaseline submission reference source. (by @saitodevel01)  \nhttps://www.kaggle.com/code/saitodevel01/gsdc2-baseline-submission","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"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-17T21:17:58.534783Z","iopub.execute_input":"2022-05-17T21:17:58.535600Z","iopub.status.idle":"2022-05-17T21:18:00.220127Z","shell.execute_reply.started":"2022-05-17T21:17:58.535550Z","shell.execute_reply":"2022-05-17T21:18:00.219109Z"},"jupyter":{"source_hidden":true},"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":{"execution":{"iopub.status.busy":"2022-05-17T21:18:00.221845Z","iopub.execute_input":"2022-05-17T21:18:00.222225Z","iopub.status.idle":"2022-05-17T21:18:00.229937Z","shell.execute_reply.started":"2022-05-17T21:18:00.222177Z","shell.execute_reply":"2022-05-17T21:18:00.229167Z"},"_kg_hide-input":true,"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-17T21:18:33.388768Z","iopub.execute_input":"2022-05-17T21:18:33.389273Z","iopub.status.idle":"2022-05-17T21:18:33.518400Z","shell.execute_reply.started":"2022-05-17T21:18:33.389221Z","shell.execute_reply":"2022-05-17T21:18:33.517576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-17T21:18:33.545500Z","iopub.execute_input":"2022-05-17T21:18:33.546232Z","iopub.status.idle":"2022-05-17T21:18:33.569505Z","shell.execute_reply.started":"2022-05-17T21:18:33.546195Z","shell.execute_reply":"2022-05-17T21:18:33.568500Z"},"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-17T21:18:30.208337Z","iopub.execute_input":"2022-05-17T21:18:30.208881Z","iopub.status.idle":"2022-05-17T21:18:30.217267Z","shell.execute_reply.started":"2022-05-17T21:18:30.208827Z","shell.execute_reply":"2022-05-17T21:18:30.216363Z"},"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-17T21:18:41.491300Z","iopub.execute_input":"2022-05-17T21:18:41.491648Z","iopub.status.idle":"2022-05-17T21:18:41.519564Z","shell.execute_reply.started":"2022-05-17T21:18:41.491613Z","shell.execute_reply":"2022-05-17T21:18:41.518449Z"},"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-17T21:19:22.994782Z","iopub.execute_input":"2022-05-17T21:19:22.995109Z","iopub.status.idle":"2022-05-17T21:19:23.002115Z","shell.execute_reply.started":"2022-05-17T21:19:22.995065Z","shell.execute_reply":"2022-05-17T21:19:23.001239Z"},"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-17T21:19:47.097879Z","iopub.execute_input":"2022-05-17T21:19:47.098405Z","iopub.status.idle":"2022-05-17T21:19:48.469062Z","shell.execute_reply.started":"2022-05-17T21:19:47.098351Z","shell.execute_reply":"2022-05-17T21:19:48.468327Z"},"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-17T21:20:01.232532Z","iopub.execute_input":"2022-05-17T21:20:01.232831Z","iopub.status.idle":"2022-05-17T21:20:01.357576Z","shell.execute_reply.started":"2022-05-17T21:20:01.232799Z","shell.execute_reply":"2022-05-17T21:20:01.356564Z"},"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-17T21:20:18.907231Z","iopub.execute_input":"2022-05-17T21:20:18.907532Z","iopub.status.idle":"2022-05-17T21:20:18.912702Z","shell.execute_reply.started":"2022-05-17T21:20:18.907500Z","shell.execute_reply":"2022-05-17T21:20:18.911650Z"},"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-17T21:20:22.995130Z","iopub.execute_input":"2022-05-17T21:20:22.995949Z","iopub.status.idle":"2022-05-17T21:20:23.085182Z","shell.execute_reply.started":"2022-05-17T21:20:22.995912Z","shell.execute_reply":"2022-05-17T21:20:23.084154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub_override.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-17T21:20:29.194512Z","iopub.execute_input":"2022-05-17T21:20:29.195475Z","iopub.status.idle":"2022-05-17T21:20:29.207339Z","shell.execute_reply.started":"2022-05-17T21:20:29.195438Z","shell.execute_reply":"2022-05-17T21:20:29.206598Z"},"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_count":null,"outputs":[]}]}