{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output.\n\nimport matplotlib.pyplot as plt\nimport matplotlib.mlab as mlab\nfrom matplotlib.colors import LogNorm\n\ndf_train = pd.read_csv('../input/train.csv')\ndf_test = pd.read_csv('../input/test.csv')"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"print(df_train[:5])\ndf_train.describe()"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"\n# Sample them for quicker visualisations\ndf_train_sample = df_train.sample(n=1000000)\ndf_test_sample = df_test.sample(n=1000000)\n\n# Check if accuracy of signal corresponds with time\nplt.figure(4, figsize=(12,10))\n\nplt.subplot(211)\nplt.scatter(df_train_sample[\"time\"], df_train_sample[\"accuracy\"], s=1, c='k', lw=0, alpha=0.1)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Accuracy\")\nplt.xlim(df_train_sample[\"time\"].min(), df_train_sample[\"time\"].max())\nplt.ylim(df_train_sample[\"accuracy\"].min(), df_train_sample[\"accuracy\"].max())\nplt.title(\"Train\")\n\nplt.subplot(212)\nplt.scatter(df_test_sample[\"time\"], df_test_sample[\"accuracy\"], s=1, c='k', lw=0, alpha=0.1)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Accuracy\")\nplt.xlim(df_test_sample[\"time\"].min(), df_test_sample[\"time\"].max())\nplt.ylim(df_test_sample[\"accuracy\"].min(), df_test_sample[\"accuracy\"].max())\nplt.title(\"Test\")\n\nplt.show()"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"# See the distribution of checkins in x and y.\nplt.figure(4, figsize=(12,12))\n\nplt.subplot(211)\nplt.scatter(df_train_sample[\"time\"], df_train_sample[\"accuracy\"], s=1, c='k', lw=0, alpha=0.1)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Accuracy\")\nplt.xlim(df_train_sample[\"time\"].min(), df_train_sample[\"time\"].max())\nplt.ylim(df_train_sample[\"accuracy\"].min(), df_train_sample[\"accuracy\"].max())\nplt.title(\"Train\")\n\nplt.subplot(212)\nplt.scatter(df_test_sample[\"time\"], df_test_sample[\"accuracy\"], s=1, c='k', lw=0, alpha=0.1)\nplt.xlabel(\"Time\")\nplt.ylabel(\"Accuracy\")\nplt.xlim(df_test_sample[\"time\"].min(), df_test_sample[\"time\"].max())\nplt.ylim(df_test_sample[\"accuracy\"].min(), df_test_sample[\"accuracy\"].max())\nplt.title(\"Test\")\n\nplt.show()"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"stats = pd.DataFrame({\n    'checkins': [0]*10000,\n    'place_cnt': 0,\n    'place_max': 0,\n    })\n\nfor i in range(100):\n    for j in range(100):\n        cell = df_train[df_train.x < 0.1 * (i+1)]\n        cell = cell [cell.x > 0.1*i]\n        cell = cell [cell.y > 0.1*j]\n        cell = cell [cell.y < 0.1 * (j+1)]\n        \n        stats.at[i*100+j, 'checkins'] = cell.x.count()\n\n        places = cell['place_id'].value_counts()\n        stats.at[i*100+j, 'place_cnt'] = places.count()\n        stats.at[i*100+j, 'place_max'] = places.max()\n        \nprint(stats)"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"place_hist = df_train['place_id'].value_counts()\nprint(place_hist.describe())\nprint\n\nfor place in place_hist[:3]:\n    print(place)\n\n"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"place_hist = df_train['place_id'].value_counts()\nplace_hist.describe()\nprint\n\nfor place in place_hist[:3].keys():\n    print(place)\n\n"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"for place in place_hist[:3].keys():\n  hotspot = df_train[df_train.place_id == place]\n\n  x = hotspot['x']\n  y = hotspot['y']\n  bins = 20\n  while bins <=40:\n      plt.hist2d(x, y, bins=bins, norm=LogNorm())\n      plt.colorbar()\n      plt.title('x and y location histogram - ' + str(bins) + ' bins')\n      plt.xlabel('x')\n      plt.ylabel('y')\n      plt.show()\n      bins = bins * 2"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"hotspot = df_train[df_train.place_id == 1308450003]\n\nx = hotspot['x']\ny = hotspot['y']\nbins = 20\nplt.hist2d(x, y, bins=bins, norm=LogNorm())\nplt.colorbar()\nplt.title('x and y location histogram - ' + str(bins) + ' bins')\nplt.xlabel('x')\nplt.ylabel('y')\nplt.show()\nbins = bins * 2"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":""}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":0}