{"cells":[
 {
  "cell_type": "markdown",
  "metadata": {},
  "source": "# The Accuracy\nIf devices were infinitely inaccurate, \nthe histogram of x and y would look flat. \nIf devices were extremely accurate, \nthe histogram of x or y would depend on the distribution of a places, \nand the number of check-ins per places,  it may look rough.\n\nI calculated the [roughness](https://en.wikipedia.org/wiki/Surface_roughness) of the histogram of 1000000 samples as the function of accuracy. \nI was expecting a monotonic function in which roughness increases as a function of accuracy. \nBut, instead I got this: \n"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "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\nplt.rcParams['figure.figsize'] = (16,5)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "train = pd.read_csv('../input/train.csv', index_col='row_id')\ntest = pd.read_csv('../input/test.csv', index_col='row_id')\ndf = pd.concat([train, test])\ndel train, test\ndf.sort_values('accuracy', inplace=True)\ndf.shape[0]"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "window = 1000000\nstep = window//10\n\nstdx = []\nstdy = []\nacc = []\nfor i in range(0,df.shape[0]-window,step):\n    stdx.append(np.histogram(df[i:(i+window)].x, bins=np.arange(0,10.001, 0.001))[0].std())\n    stdy.append(np.histogram(df[i:(i+window)].y, bins=np.arange(0,10.001, 0.001))[0].std())\n    acc.append(df[i:(i+window)].accuracy.mean())"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "plt.axvline(15, color='gray')\nplt.axvline(38, color='gray')\nplt.axvline(160, color='gray')\n\nplt.semilogx(acc, np.array(stdx))\nplt.semilogx(acc, np.array(stdy))\nplt.xlabel('accuracy')\nplt.ylabel('roughness')\nplt.legend(['x', 'y'])"
 },
 {
  "cell_type": "markdown",
  "metadata": {},
  "source": "The highest roughness happens around accuracy = 160. The second peak is at about accuracy = 38."
 }
],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}}, "nbformat": 4, "nbformat_minor": 0}