{"cells":[
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "import numpy as np\nimport pandas as pd\nimport os\nimport matplotlib.pyplot as plt\n%matplotlib inline\nfrom scipy.stats import gaussian_kde\nimport time\nimport seaborn as sbn"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# loading data\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": "# checking the trainning data \ndf_train.head(5)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# checking the test data\ndf_test.head(5)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# information from the above tables:\n# (1) x, y, accuracy and time are used to predict place_id\n# (2) x, y stands for location, time is time, and accuracy is used to measure the location accuracy"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# (1) check the accuracy data distribution"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "count1, bin1 = np.histogram(df_train['accuracy'], bins=50)\nbinc1 = bin1[:-1]+np.diff(bin1)/2"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "count2, bin2 =np.histogram(df_test['accuracy'],bins=50)\nbinc2=bin2[:-1]+np.diff(bin2)/2\n                                   "
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "plt.figure(0, figsize = (12,4))\nplt.subplot(121)\nplt.bar(binc1,count1/(count1.sum()*1.0),width=np.diff(bin1)[0])\nplt.xlabel('Accuracy')\nplt.ylabel('Fraction')\nplt.title('Trainning Data')\n\nplt.subplot(122)\nplt.bar(binc2,count2/(count2.sum()*1.0),width=np.diff(bin2)[0])\nplt.xlabel('Accuracy')\nplt.ylabel('Fraction')\nplt.title('Testing Data')\n\nplt.show()"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# data pattern in trainning set is very similar to that in testing data"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# (2) checking the time distribution"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "count3, bin3 = np.histogram(df_train['time'], bins=50)\nbinc3 = bin3[:-1] +np.diff(bin3)/2\n\ncount4,bin4 = np.histogram(df_test['time'], bins=50)\nbinc4 = bin4[:-1] +np.diff(bin4)/2\n\nplt.figure(1, figsize =(12,4))\n\nplt.subplot(121)\nplt.bar(binc3,count3/(count3.sum()*1.0),width = np.diff(bin3)[0], color = 'g')\nplt.xlabel('Time')\nplt.ylabel('Fraction')\nplt.title('Trainning data')\n\nplt.subplot(122)\nplt.bar(binc4,count4/(count4.sum()*1.0),width = np.diff(bin4)[0], color = 'b')\nplt.xlabel('Time')\nplt.ylabel('Fraction')\nplt.title('Testing data')\n\nplt.show()"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "plt.figure(2,figsize=(12,4))\nplt.bar(binc3,count3/(count3.sum()*1.0),width=np.diff(binc3)[0],color = 'g',label='Training')\nplt.bar(binc4, count4/(count4.sum()*1.0),width=np.diff(binc4)[0],color='b',label='Testing')\nplt.xlabel('Time')\nplt.ylabel('Fraction')\nplt.title('Test')\nplt.legend()\nplt.show()"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# check how frequently different locations appear\n\ndf_pcounts = df_train['place_id'].value_counts()\n\ncount5, bin5 = np.histogram(df_pcounts.values, bins =50)\nbinc5 = bin5[:-1] + np.diff(bin5)/2\n\nplt.figure(3, figsize=(12,4))\nplt.bar(binc5,count5/(count5.sum()*1.0), width=np.diff(bin5)[0])\nplt.xlabel('Number of place occurances')\nplt.ylabel('Fraction')\nplt.title('Tranning data')\nplt.show()"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# checking how accuracy of signal changes with time\n\nplt.figure(4,figsize=(12,4))\nplt.scatter(df_train['time'], df_train['accuracy'], s=1, c='g', alpha=0.1, label='Trainning')\nplt.scatter(df_test['time'], df_test['accuracy'], s=1, c='b', alpha =0.1, label='Testing')\nplt.xlabel('Time')\nplt.ylabel('Accuracy')\nplt.title('Accuracy-Time')\nplt.legend()\n\nplt.show()"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# accuracy vs. location\ndf_train['xround'] = df_trai"
 }
],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}}, "nbformat": 4, "nbformat_minor": 0}