{"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":"<h3> WIP NOTEBOOK CONTENTS </h3>\n\n<img src = \"https://i.imgur.com/EJj8QCN.png\" ></img>\n\nThis is a simple Notebook to show Baseline Location in the world using the `folium` package.\n\n<div id=\"toc_container\" style=\"background: #f9f9f9; border: 1px solid #aaa; display: table; font-size: 95%;\n                               margin-bottom: 1em; padding: 20px; width: auto;\">\n<p class=\"toc_title\" style=\"font-weight: 700; text-align: center\">Notebook Contents</p>\n<ul class=\"toc_list\">\n  <li><a href=\"#baseline\">1. Baseline Locations </a>\n      <br>\n      <ul>\n    <li><a href=\"#baseline_geo\">1.1 Geo Locations</a></li>\n    <li><a href=\"#baseline_eda\">1.2 Data Exploration</a></li>\n  </ul>\n</li>\n</ul>\n</div>","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport os\nroot_path = '/kaggle/input/google-smartphone-decimeter-challenge'\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id = \"baseline\">","metadata":{}},{"cell_type":"code","source":"baseline_locations_train = pd.read_csv(root_path + \"/baseline_locations_train.csv\")\nbaseline_locations_test = pd.read_csv(root_path + \"/baseline_locations_test.csv\")\ndisplay(baseline_locations_train.sample(3))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id = 'baseline_eda'></a>","metadata":{}},{"cell_type":"markdown","source":"<a id = 'baseline_geo'></a>\n<h5> Example of Locations: test (blue) vs train (orange) </h5>","metadata":{}},{"cell_type":"code","source":"import folium\n\nm = folium.Map(location=[37.453128,-122.154313], tiles='openstreetmap', zoom_start = 10)\n\nsample_locations_test = baseline_locations_test.sample(200).reset_index(drop = True)\nsample_locations_train = baseline_locations_train.sample(200).reset_index(drop = True)\n\nfor j in range(len(sample_locations_test)):\n    try:\n        folium.Marker(location=[sample_locations_test['latDeg'][j],\n                                sample_locations_test['lngDeg'][j]],\n                        popup=sample_locations_test['collectionName'][j],\n                        icon = folium.Icon(prefix = 'fa', icon = \"map-pin\", color = 'lightblue'),\n                        fill_color='#132b5e', num_sides=3, radius=3).add_to(m)\n    except:\n        continue\n        \nfor j in range(len(sample_locations_train)):\n    try:\n        folium.Marker(location=[sample_locations_train['latDeg'][j],\n                                sample_locations_train['lngDeg'][j]],\n                        popup=sample_locations_train['collectionName'][j],\n                        icon = folium.Icon(prefix = 'fa', icon = \"map-pin\", color = 'orange'),\n                        fill_color='#132b5e', num_sides=3, radius=3).add_to(m)\n    except:\n        continue\nm","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id = \"baseline\"></a>\n<h5> baseline_locations Exploration </h5>","metadata":{}},{"cell_type":"code","source":"pn_train = (baseline_locations_train.groupby('phoneName').agg({'phone': ['nunique', 'count']})\n            .reset_index(drop = False))\npn_train.columns = ['phoneName', 'unique_devices', 'n_rows']\npn_train = pn_train.assign(dataset='train')\n\npn_test = (baseline_locations_test.groupby('phoneName').agg({'phone': ['nunique', 'count']})\n            .reset_index(drop = False))\npn_test.columns = ['phoneName', 'unique_devices', 'n_rows']\npn_test = pn_test.assign(dataset='test')\n\n\npn_dist = pd.concat([pn_train, pn_test], axis = 0, ignore_index = True)\n\ncmap_plot = plt.get_cmap('jet_r')\nplt.style.use('fivethirtyeight')\n\nprint(\"Number of unique devices per phoneName\")\nfig, (ax0, ax1) = plt.subplots(1, 2, figsize=(18, 6),gridspec_kw={'width_ratios': [1.5, 1.5]})\nsns.barplot(x = 'phoneName', y = 'unique_devices', data = pn_dist, hue = 'dataset', ax = ax0)\n\nax0.set_xlim([-1, 7])\nax0.set_ylabel('Number of unique devices')\nax0.set_xticklabels(pn_dist.phoneName.unique().tolist(), rotation = 45)\n\nfont_size=12\nbbox=[-0.2, 0, 1.2, 0.7]\nax1.axis('off')\nccolors = plt.cm.BuPu(np.full(len(pn_dist.columns), 0.1))\nmpl_table = ax1.table(cellText = pn_dist.values, bbox=bbox, colLabels=pn_dist.columns, colColours=ccolors)\nmpl_table.auto_set_font_size(True)\n#mpl_table.set_fontsize(font_size)","metadata":{"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]}]}