{"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\nimport matplotlib\nmatplotlib.use('TkAgg')\n\nfrom scipy import stats, integrate\nimport matplotlib.pyplot as plt\nimport pylab\nimport seaborn as sns # A Python visualization library based on matplotlib\nsns.set(color_codes=True)\n\n\nFIG_PATH = \"../output\"\n\n\"\"\"\nA method to plot the distribution\nof a variable\n@param : array of numerical variable\n@param : fig_name. if false, plot won't be saved.\n@return : plot interactive window\n\"\"\"\n\ndef distribution_plot(x, fig_name):\n    fig = sns.distplot(x)\n    if fig_name:\n        plt.savefig(FIG_PATH + fig_name + '.png')\n        plt.close()\n    else:\n        sns.plt.show()\n\ndef save_and_close(fig_name):\n    plt.savefig(FIG_PATH + fig_name + '.png')\n    plt.close\n\ndef plot_xy_by_place_id(df, place_id):\n    index = df[\"place_id\"] ==  place_id;\n    plt.scatter(df['x'][index], df['y'][index])\n\ndf_train = pd.read_csv(\"../input/train.csv\")\nnRows = len(df_train);\n\n\n\nunique_place_id = set(df_train['place_id'])\nlist_unique_place_id = list(unique_place_id)\nprint(len(unique_place_id))\n\nprint('So we expect approximatively ' +  str(nRows/len(unique_place_id)) + ' row_id per place_id')\n\n# -------   Define a smaller dataset -------\n# It will allow to be more agile with\n# the methods we'll test\n\nboots = np.random.randint(1, nRows, int(0.0001*nRows))\ndf_small = df_train.iloc[boots, ];\nplt.scatter(df_small['x'], df_small['y']) # random 2D-uniform distribution.\n\n\n# ----- Location and place_id ------\n# Let's take the first place_id of the dataset and check the (x, y)\n# distribution for this place_id only.\n\n\nind = 0;\nplot_xy_by_place_id(df_train, list_unique_place_id[ind])\ntitle = 'x_y_' + str( list_unique_place_id[ind]) + '_place_id'\nsave_and_close(title)\n\nind = np.random.randint(1, len(list_unique_place_id));\nplot_xy_by_place_id(df_train, list_unique_place_id[ind])\ntitle = 'x_y_' + str( list_unique_place_id[ind]) + '_place_id'\nsave_and_close(title)\n\nind = np.random.randint(1, len(list_unique_place_id));\nplot_xy_by_place_id(df_train, list_unique_place_id[ind])\ntitle = 'x_y_' + str( list_unique_place_id[ind]) + '_place_id'\nsave_and_close(title)\n\n\n\n\n\n\n"
 }
],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}}, "nbformat": 4, "nbformat_minor": 0}