{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-05T14:53:39.028460Z","iopub.execute_input":"2023-01-05T14:53:39.028975Z","iopub.status.idle":"2023-01-05T14:53:41.830526Z","shell.execute_reply.started":"2023-01-05T14:53:39.028939Z","shell.execute_reply":"2023-01-05T14:53:41.829240Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport os\n!pip install folium\n!pip install simdkalman\nimport pickle\nimport sys\nimport warnings\nfrom glob import glob\nimport requests\nimport folium\nfrom shapely.geometry import Point,shape\nimport shapely.wkt\nfrom geopandas import GeoDataFrame\nimport simdkalman\nimport shap\nimport xgboost\nfrom scipy.stats import spearmanr\nfrom sklearn.ensemble import(\nExtraTreesRegressor,GradientBoostingRegressor,RandomForestRegressor)\nfrom sklearn.metrics import accuracy_score,mean_squared_error\nfrom tqdm.notebook import tqdm\npd.options.mode.use_inf_as_na=True\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:53:41.833499Z","iopub.execute_input":"2023-01-05T14:53:41.834791Z","iopub.status.idle":"2023-01-05T14:54:12.908127Z","shell.execute_reply.started":"2023-01-05T14:53:41.834735Z","shell.execute_reply":"2023-01-05T14:54:12.906812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:12.910085Z","iopub.execute_input":"2023-01-05T14:54:12.910752Z","iopub.status.idle":"2023-01-05T14:54:12.916146Z","shell.execute_reply.started":"2023-01-05T14:54:12.910715Z","shell.execute_reply":"2023-01-05T14:54:12.915130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('../input/smartphone-decimeter-2022/sample_submission.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:12.917652Z","iopub.execute_input":"2023-01-05T14:54:12.918045Z","iopub.status.idle":"2023-01-05T14:54:13.013770Z","shell.execute_reply.started":"2023-01-05T14:54:12.918006Z","shell.execute_reply":"2023-01-05T14:54:13.012764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.017293Z","iopub.execute_input":"2023-01-05T14:54:13.018068Z","iopub.status.idle":"2023-01-05T14:54:13.053458Z","shell.execute_reply.started":"2023-01-05T14:54:13.018026Z","shell.execute_reply":"2023-01-05T14:54:13.052044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['tripId'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.054961Z","iopub.execute_input":"2023-01-05T14:54:13.055343Z","iopub.status.idle":"2023-01-05T14:54:13.069927Z","shell.execute_reply.started":"2023-01-05T14:54:13.055310Z","shell.execute_reply":"2023-01-05T14:54:13.068412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=df.iloc[:,[2,3]].values\nprint(X)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.071940Z","iopub.execute_input":"2023-01-05T14:54:13.072339Z","iopub.status.idle":"2023-01-05T14:54:13.085245Z","shell.execute_reply.started":"2023-01-05T14:54:13.072305Z","shell.execute_reply":"2023-01-05T14:54:13.083720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=df.iloc[:,0:4].values\nprint(y)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.086751Z","iopub.execute_input":"2023-01-05T14:54:13.087144Z","iopub.status.idle":"2023-01-05T14:54:13.119443Z","shell.execute_reply.started":"2023-01-05T14:54:13.087110Z","shell.execute_reply":"2023-01-05T14:54:13.118351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\ncname_=glob('../input/smartphone-decimeter-2022/train/*')\ntmp=[]\nfor i in cname_:\n    tmp.extend(glob(f'{i}/*'))\ncname=[]\nfor r in tmp:\n    cname.append([r.split('/')[4],r.split('/')[5]])\ncname=pd.DataFrame(sorted(cname))\ncname\n                    ","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.120768Z","iopub.execute_input":"2023-01-05T14:54:13.121940Z","iopub.status.idle":"2023-01-05T14:54:13.194799Z","shell.execute_reply.started":"2023-01-05T14:54:13.121896Z","shell.execute_reply":"2023-01-05T14:54:13.193083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cname[1].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.196612Z","iopub.execute_input":"2023-01-05T14:54:13.197098Z","iopub.status.idle":"2023-01-05T14:54:13.208910Z","shell.execute_reply.started":"2023-01-05T14:54:13.197050Z","shell.execute_reply":"2023-01-05T14:54:13.207478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from glob import glob\ncname_=glob('../input/smartphone-decimeter-2022/test/*')\ntmp=[]\nfor i in cname_:\n    tmp.extend(glob(f'{i}/*'))\ncname=[]\nfor r in tmp:\n    cname.append([r.split('/')[4],r.split('/')[5]])\ncname=pd.DataFrame(sorted(cname))\ncname[1].value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.210160Z","iopub.execute_input":"2023-01-05T14:54:13.210642Z","iopub.status.idle":"2023-01-05T14:54:13.286966Z","shell.execute_reply.started":"2023-01-05T14:54:13.210573Z","shell.execute_reply":"2023-01-05T14:54:13.285574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nraw=open('../input/smartphone-decimeter-2022/metadata/raw_state_bit_map.json','r')\njson.load(raw)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.288334Z","iopub.execute_input":"2023-01-05T14:54:13.288741Z","iopub.status.idle":"2023-01-05T14:54:13.300332Z","shell.execute_reply.started":"2023-01-05T14:54:13.288701Z","shell.execute_reply":"2023-01-05T14:54:13.298997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nbit=open('../input/smartphone-decimeter-2022/metadata/accumulated_delta_range_state_bit_map.json','r')\njson.load(bit)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.301984Z","iopub.execute_input":"2023-01-05T14:54:13.302485Z","iopub.status.idle":"2023-01-05T14:54:13.314471Z","shell.execute_reply.started":"2023-01-05T14:54:13.302433Z","shell.execute_reply":"2023-01-05T14:54:13.312934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mapping=pd.read_csv('../input/smartphone-decimeter-2022/metadata/constellation_type_mapping.csv')\nmapping","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.320897Z","iopub.execute_input":"2023-01-05T14:54:13.321320Z","iopub.status.idle":"2023-01-05T14:54:13.338105Z","shell.execute_reply.started":"2023-01-05T14:54:13.321280Z","shell.execute_reply":"2023-01-05T14:54:13.336604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ground=pd.read_csv('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/ground_truth.csv')\nground","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.340202Z","iopub.execute_input":"2023-01-05T14:54:13.341274Z","iopub.status.idle":"2023-01-05T14:54:13.386591Z","shell.execute_reply.started":"2023-01-05T14:54:13.341223Z","shell.execute_reply":"2023-01-05T14:54:13.385112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imu=pd.read_csv('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/device_imu.csv')\nimu","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:13.388840Z","iopub.execute_input":"2023-01-05T14:54:13.389352Z","iopub.status.idle":"2023-01-05T14:54:14.993092Z","shell.execute_reply.started":"2023-01-05T14:54:13.389305Z","shell.execute_reply":"2023-01-05T14:54:14.991717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gnss=pd.read_csv('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/device_gnss.csv')\ngnss","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:14.994749Z","iopub.execute_input":"2023-01-05T14:54:14.995123Z","iopub.status.idle":"2023-01-05T14:54:17.146162Z","shell.execute_reply.started":"2023-01-05T14:54:14.995090Z","shell.execute_reply":"2023-01-05T14:54:17.144834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import folium\nfrom folium import plugins\ndf_locs=list(ground[['LatitudeDegrees','LongitudeDegrees']].values)\nfol_map=folium.Map([ground['LatitudeDegrees'].median(),ground['LongitudeDegrees'].median()],zoom_start=11)\nheat_map=plugins.HeatMap(df_locs)\nfol_map.add_child(heat_map)\nmarkers=plugins.MarkerCluster(locations=df_locs)\nfol_map.add_child(markers)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:17.148019Z","iopub.execute_input":"2023-01-05T14:54:17.148378Z","iopub.status.idle":"2023-01-05T14:54:19.510277Z","shell.execute_reply.started":"2023-01-05T14:54:17.148343Z","shell.execute_reply":"2023-01-05T14:54:19.508014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f=open('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/supplemental/gnss_log.txt','r')\nlog=f.read()\nf.close()\nlog[:500]","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:19.511783Z","iopub.execute_input":"2023-01-05T14:54:19.513226Z","iopub.status.idle":"2023-01-05T14:54:20.304372Z","shell.execute_reply.started":"2023-01-05T14:54:19.513181Z","shell.execute_reply":"2023-01-05T14:54:20.303093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path='../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/supplemental/gnss_log.txt'\ngnss_section_names={'Raw','UncalAccel','UncalGyro','UncalMag','Fix','Status','OrientationDeg'}\nwith open(path) as f_open:\n    datalines=f_open.readlines()\n    \ndatas={k:[] for k in gnss_section_names}\ngnss_map={k:[] for k in gnss_section_names}\nfor dataline in datalines:\n    if dataline !='' and dataline[0] != '':\n        is_header=dataline.startswith('#')\n        dataline=dataline.strip('#').strip().split(',')\n        if is_header and dataline[0] in gnss_section_names:\n            gnss_map[dataline[0]]=dataline[1:]\n        elif not is_header:\n            if dataline != '' and dataline[0] != '':\n                datas[dataline[0]].append(dataline[1:])\nresults=dict()\nfor k,v in datas.items():\n    results[k]=pd.DataFrame(v,columns=gnss_map[k])\nfor k,df in results.items():\n    for col in df.columns:\n        if col=='CodeType':\n            continue\n        results[k][col]=pd.to_numeric(results[k][col])","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:20.305723Z","iopub.execute_input":"2023-01-05T14:54:20.306075Z","iopub.status.idle":"2023-01-05T14:54:30.581208Z","shell.execute_reply.started":"2023-01-05T14:54:20.306041Z","shell.execute_reply":"2023-01-05T14:54:30.579862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['Raw']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.583717Z","iopub.execute_input":"2023-01-05T14:54:30.585075Z","iopub.status.idle":"2023-01-05T14:54:30.649876Z","shell.execute_reply.started":"2023-01-05T14:54:30.585017Z","shell.execute_reply":"2023-01-05T14:54:30.648339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['UncalAccel']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.651713Z","iopub.execute_input":"2023-01-05T14:54:30.652094Z","iopub.status.idle":"2023-01-05T14:54:30.677231Z","shell.execute_reply.started":"2023-01-05T14:54:30.652056Z","shell.execute_reply":"2023-01-05T14:54:30.675841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['UncalGyro']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.678958Z","iopub.execute_input":"2023-01-05T14:54:30.679845Z","iopub.status.idle":"2023-01-05T14:54:30.703639Z","shell.execute_reply.started":"2023-01-05T14:54:30.679808Z","shell.execute_reply":"2023-01-05T14:54:30.701914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['UncalMag']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.705119Z","iopub.execute_input":"2023-01-05T14:54:30.706492Z","iopub.status.idle":"2023-01-05T14:54:30.732822Z","shell.execute_reply.started":"2023-01-05T14:54:30.706438Z","shell.execute_reply":"2023-01-05T14:54:30.731444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['Fix']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.734919Z","iopub.execute_input":"2023-01-05T14:54:30.735300Z","iopub.status.idle":"2023-01-05T14:54:30.750598Z","shell.execute_reply.started":"2023-01-05T14:54:30.735266Z","shell.execute_reply":"2023-01-05T14:54:30.748480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['Status']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.752358Z","iopub.execute_input":"2023-01-05T14:54:30.752813Z","iopub.status.idle":"2023-01-05T14:54:30.765343Z","shell.execute_reply.started":"2023-01-05T14:54:30.752766Z","shell.execute_reply":"2023-01-05T14:54:30.764047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results['OrientationDeg']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.767782Z","iopub.execute_input":"2023-01-05T14:54:30.768331Z","iopub.status.idle":"2023-01-05T14:54:30.784424Z","shell.execute_reply.started":"2023-01-05T14:54:30.768279Z","shell.execute_reply":"2023-01-05T14:54:30.782823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f=open('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/supplemental/gnss_rinex.20o','r')\nrinex=f.read()\nf.close()\nrinex[:500]","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.786534Z","iopub.execute_input":"2023-01-05T14:54:30.787238Z","iopub.status.idle":"2023-01-05T14:54:30.884406Z","shell.execute_reply.started":"2023-01-05T14:54:30.787181Z","shell.execute_reply":"2023-01-05T14:54:30.883464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rinex=pd.read_csv('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/supplemental/gnss_rinex.20o')\nrinex","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:30.885983Z","iopub.execute_input":"2023-01-05T14:54:30.886329Z","iopub.status.idle":"2023-01-05T14:54:31.014767Z","shell.execute_reply.started":"2023-01-05T14:54:30.886292Z","shell.execute_reply":"2023-01-05T14:54:31.013166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"f=open('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/supplemental/span_log.nmea')\nspan=f.read()\nf.close()\nspan[:500]\n\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:31.016714Z","iopub.execute_input":"2023-01-05T14:54:31.017535Z","iopub.status.idle":"2023-01-05T14:54:31.041662Z","shell.execute_reply.started":"2023-01-05T14:54:31.017455Z","shell.execute_reply":"2023-01-05T14:54:31.040357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"span=pd.read_csv('../input/smartphone-decimeter-2022/train/2020-05-15-US-MTV-1/GooglePixel4XL/supplemental/span_log.nmea')\nspan\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:31.043310Z","iopub.execute_input":"2023-01-05T14:54:31.043853Z","iopub.status.idle":"2023-01-05T14:54:31.097270Z","shell.execute_reply.started":"2023-01-05T14:54:31.043803Z","shell.execute_reply":"2023-01-05T14:54:31.095744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nsub=pd.read_csv('../input/smartphone-decimeter-2022/sample_submission.csv')\nsub","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:54:31.098954Z","iopub.execute_input":"2023-01-05T14:54:31.099452Z","iopub.status.idle":"2023-01-05T14:54:31.179024Z","shell.execute_reply.started":"2023-01-05T14:54:31.099402Z","shell.execute_reply":"2023-01-05T14:54:31.177602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\npd.read_csv('../input/smartphone-decimeter-2022/train/2020-08-06-US-MTV-2/GooglePixel4/ground_truth.csv')\n","metadata":{"execution":{"iopub.status.busy":"2023-01-05T14:59:23.187491Z","iopub.execute_input":"2023-01-05T14:59:23.187988Z","iopub.status.idle":"2023-01-05T14:59:23.222459Z","shell.execute_reply.started":"2023-01-05T14:59:23.187950Z","shell.execute_reply":"2023-01-05T14:59:23.221466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r=requests.get(\"https://data.sfgov.org/api/views/wamw-vt4s/rows.json?accessType=DOWNLOAD\")\nr.raise_for_status()\ndata=r.json()\nshapes=[]\nfor d in data[\"data\"]:\n    shapes.append(shapely.wkt.loads(d[8]))\ngdf_bayarea=pd.DataFrame()\nfor shp in shapes[5:7]:\n    tmp=pd.DataFrame(shp,columns=[\"geometry\"])\n    gdf_bayarea=pd.concat([gdf_bayarea,tmp])\ngdf_bayarea=GeoDataFrame(gdf_bayarea)\n    ","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:07:00.169228Z","iopub.execute_input":"2023-01-05T15:07:00.169651Z","iopub.status.idle":"2023-01-05T15:07:01.071140Z","shell.execute_reply.started":"2023-01-05T15:07:00.169617Z","shell.execute_reply":"2023-01-05T15:07:01.069703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gdf_bayarea","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:07:11.313310Z","iopub.execute_input":"2023-01-05T15:07:11.313751Z","iopub.status.idle":"2023-01-05T15:07:11.367045Z","shell.execute_reply.started":"2023-01-05T15:07:11.313717Z","shell.execute_reply":"2023-01-05T15:07:11.365871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%capture\ncollectionNames=[item.split(\"/\")[-1] for item in glob(\"../input/smartphone-decimeter-2022/train/*\")]\ngdfs=[]\nfor collectionName in collectionNames:\n    gdfs_each_collectionName=[]\n    csv_paths=glob(f\"../input/smartphone-decimeter-2022/train/{collectionName}/*/ground_truth.csv\")\n    for csv_path in csv_paths:\n        df_gt=pd.read_csv(csv_path)\n        df_gt[\"geometry\"]=[Point(lngDeg,latDeg) for lngDeg,latDeg in zip(df_gt[\"LatitudeDegrees\"],df_gt[\"LongitudeDegrees\"])]\n        gdfs_each_collectionName.append(GeoDataFrame(df_gt))\n    gdfs.append(gdfs_each_collectionName)\ncolors=[\"blue\",\"green\",\"purple\",\"orange\"]","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:51:13.492434Z","iopub.execute_input":"2023-01-05T15:51:13.493646Z","iopub.status.idle":"2023-01-05T15:51:36.158927Z","shell.execute_reply.started":"2023-01-05T15:51:13.493587Z","shell.execute_reply":"2023-01-05T15:51:36.157820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gdfs_each_collectionName","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:52:01.005731Z","iopub.execute_input":"2023-01-05T15:52:01.006164Z","iopub.status.idle":"2023-01-05T15:52:01.063434Z","shell.execute_reply.started":"2023-01-05T15:52:01.006127Z","shell.execute_reply":"2023-01-05T15:52:01.062086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for collectionName,gdfs_each_collectionName in zip(collectionNames,gdfs):\n    fig,axs=plt.subplots(1,2,figsize=(15,5))\n    gdf_bayarea.plot(figsize=(10,10),color='none',edgecolor='gray',zorder=5,ax=axs[0])\n    for i,gdf in enumerate(gdfs_each_collectionName):\n        g2=gdf.plot(color=colors[i],ax=axs[1])\n        g2.set_title(f\"Phone track of {collectionName}\")","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:58:07.577331Z","iopub.execute_input":"2023-01-05T15:58:07.577752Z","iopub.status.idle":"2023-01-05T15:59:38.976961Z","shell.execute_reply.started":"2023-01-05T15:58:07.577720Z","shell.execute_reply":"2023-01-05T15:59:38.975397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2023-01-05T15:59:39.130368Z","iopub.execute_input":"2023-01-05T15:59:39.130867Z","iopub.status.idle":"2023-01-05T15:59:39.143565Z","shell.execute_reply.started":"2023-01-05T15:59:39.130808Z","shell.execute_reply":"2023-01-05T15:59:39.142320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf=pd.read_csv('../input/smartphone-decimeter-2022/sample_submission.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:00:35.015284Z","iopub.execute_input":"2023-01-05T16:00:35.015739Z","iopub.status.idle":"2023-01-05T16:00:35.087211Z","shell.execute_reply.started":"2023-01-05T16:00:35.015701Z","shell.execute_reply":"2023-01-05T16:00:35.085921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:00:45.775012Z","iopub.execute_input":"2023-01-05T16:00:45.775440Z","iopub.status.idle":"2023-01-05T16:00:45.796182Z","shell.execute_reply.started":"2023-01-05T16:00:45.775405Z","shell.execute_reply":"2023-01-05T16:00:45.794944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['tripId'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:01:13.672873Z","iopub.execute_input":"2023-01-05T16:01:13.673427Z","iopub.status.idle":"2023-01-05T16:01:13.690071Z","shell.execute_reply.started":"2023-01-05T16:01:13.673378Z","shell.execute_reply":"2023-01-05T16:01:13.688610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=df[['UnixTimeMillis','LatitudeDegrees','LongitudeDegrees']]\ny=df['tripId']","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:02:30.994124Z","iopub.execute_input":"2023-01-05T16:02:30.994612Z","iopub.status.idle":"2023-01-05T16:02:31.002927Z","shell.execute_reply.started":"2023-01-05T16:02:30.994573Z","shell.execute_reply":"2023-01-05T16:02:31.001569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=0)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:02:37.979421Z","iopub.execute_input":"2023-01-05T16:02:37.979859Z","iopub.status.idle":"2023-01-05T16:02:37.997216Z","shell.execute_reply.started":"2023-01-05T16:02:37.979819Z","shell.execute_reply":"2023-01-05T16:02:37.995745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import lightgbm as lgb\nclf=lgb.LGBMClassifier()\nclf.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:02:40.040960Z","iopub.execute_input":"2023-01-05T16:02:40.042422Z","iopub.status.idle":"2023-01-05T16:02:49.948846Z","shell.execute_reply.started":"2023-01-05T16:02:40.042367Z","shell.execute_reply":"2023-01-05T16:02:49.947258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=clf.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:02:52.745547Z","iopub.execute_input":"2023-01-05T16:02:52.745954Z","iopub.status.idle":"2023-01-05T16:02:56.001987Z","shell.execute_reply.started":"2023-01-05T16:02:52.745921Z","shell.execute_reply":"2023-01-05T16:02:56.000905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy=accuracy_score(y_pred,y_test)\nprint('LightGBM Model Accuracy score:{0:0.4f}'.format(accuracy_score(y_test,y_pred)))","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:01.314520Z","iopub.execute_input":"2023-01-05T16:03:01.314930Z","iopub.status.idle":"2023-01-05T16:03:01.370959Z","shell.execute_reply.started":"2023-01-05T16:03:01.314895Z","shell.execute_reply":"2023-01-05T16:03:01.369613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_train=clf.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:06.906084Z","iopub.execute_input":"2023-01-05T16:03:06.906498Z","iopub.status.idle":"2023-01-05T16:03:14.685781Z","shell.execute_reply.started":"2023-01-05T16:03:06.906463Z","shell.execute_reply":"2023-01-05T16:03:14.684449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Training-set accuracy score:{0:0.4f}'.format(accuracy_score(y_train,y_pred_train)))","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:21.314343Z","iopub.execute_input":"2023-01-05T16:03:21.314812Z","iopub.status.idle":"2023-01-05T16:03:21.376831Z","shell.execute_reply.started":"2023-01-05T16:03:21.314774Z","shell.execute_reply":"2023-01-05T16:03:21.375484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Training set score:{:.4f}'.format(clf.score(X_train,y_train)))\nprint('Test set score:{:.4f}'.format(clf.score(X_test,y_test)))","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:23.232708Z","iopub.execute_input":"2023-01-05T16:03:23.233147Z","iopub.status.idle":"2023-01-05T16:03:34.132264Z","shell.execute_reply.started":"2023-01-05T16:03:23.233111Z","shell.execute_reply":"2023-01-05T16:03:34.131021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix\ncm=confusion_matrix(y_test,y_pred)\nprint('Confusion matrix\\n\\n',cm)\nprint('\\n True Positives(TP)= ',cm[0,0])\nprint('\\n True Negatives(TN)= ',cm[1,1])\nprint('\\n False Positives(FP)= ',cm[0,1])\nprint('\\n False Negatives(FN)= ',cm[1,0])","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:35.805866Z","iopub.execute_input":"2023-01-05T16:03:35.806298Z","iopub.status.idle":"2023-01-05T16:03:35.897820Z","shell.execute_reply.started":"2023-01-05T16:03:35.806261Z","shell.execute_reply":"2023-01-05T16:03:35.896567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.utils.multiclass import unique_labels\nunique_labels(y_test)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:39.714694Z","iopub.execute_input":"2023-01-05T16:03:39.715087Z","iopub.status.idle":"2023-01-05T16:03:39.745575Z","shell.execute_reply.started":"2023-01-05T16:03:39.715055Z","shell.execute_reply":"2023-01-05T16:03:39.744322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot(y_true,y_pred):\n    labels=unique_labels(y_test)\n    columns=[f'Predicted{label}' for label in labels]\n    index=[f'Actual{label}' for label in labels]\n    table=pd.DataFrame(confusion_matrix(y_true,y_pred),columns=columns,index=index)\n    return table","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:46.387359Z","iopub.execute_input":"2023-01-05T16:03:46.388612Z","iopub.status.idle":"2023-01-05T16:03:46.396616Z","shell.execute_reply.started":"2023-01-05T16:03:46.388555Z","shell.execute_reply":"2023-01-05T16:03:46.394911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:47.939964Z","iopub.execute_input":"2023-01-05T16:03:47.940491Z","iopub.status.idle":"2023-01-05T16:03:48.086840Z","shell.execute_reply.started":"2023-01-05T16:03:47.940383Z","shell.execute_reply":"2023-01-05T16:03:48.085645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:53.798653Z","iopub.execute_input":"2023-01-05T16:03:53.799103Z","iopub.status.idle":"2023-01-05T16:03:53.805620Z","shell.execute_reply.started":"2023-01-05T16:03:53.799064Z","shell.execute_reply":"2023-01-05T16:03:53.803972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot2(y_true,y_pred):\n    labels=unique_labels(y_test)\n    column=[f'Predicted{label}' for label in labels]\n    indices=[f'Actual{label}' for label in labels]\n    table=pd.DataFrame(confusion_matrix(y_true,y_pred),columns=column,index=indices)\n    return sns.heatmap(table,annot=True,fmt='d',cmap='viridis')","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:56.855912Z","iopub.execute_input":"2023-01-05T16:03:56.856321Z","iopub.status.idle":"2023-01-05T16:03:56.863995Z","shell.execute_reply.started":"2023-01-05T16:03:56.856284Z","shell.execute_reply":"2023-01-05T16:03:56.862738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot2(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:03:59.115679Z","iopub.execute_input":"2023-01-05T16:03:59.116137Z","iopub.status.idle":"2023-01-05T16:04:04.712785Z","shell.execute_reply.started":"2023-01-05T16:03:59.116097Z","shell.execute_reply":"2023-01-05T16:04:04.711790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report\nprint(classification_report(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2023-01-05T16:04:05.342874Z","iopub.execute_input":"2023-01-05T16:04:05.343642Z","iopub.status.idle":"2023-01-05T16:04:05.968408Z","shell.execute_reply.started":"2023-01-05T16:04:05.343594Z","shell.execute_reply":"2023-01-05T16:04:05.967143Z"},"trusted":true},"execution_count":null,"outputs":[]}]}