{"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\n# Load the training data set\ndata = pd.read_csv(\"../input/train.csv\")\nplaces = data['place_id']\nfeatures = data.drop(['place_id', 'row_id'], axis = 1)\n\n#== DATA EXPLORATION\ndta = data\ndta['freq'] = dta.groupby('place_id')['x'].transform('count')\ndta['hour'] = (dta['time'] / 60) % 24\ndta['weekday'] = (dta['time'] / (60*24)) % 7\ndta['month'] = (dta['time'] / (60*24*30)) % 12\ndta['year'] = dta['time'] / (60*24*365)\ndta['day'] = (dta['time'] / (60*24)) % 365\n#dta['x_combo_y'] = ((dta['x']*1)+(dta['y']*10))/(10.049876)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "print( dta[:5])\n\n# DATA VISUALIZATION\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom plotly import tools\n\n#fig = plt.figure(figsize=(16,10))\nhalfSize = int(len(range(100, 140, 40)) / 2)\n\nimport math\nimport itertools\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.multiclass import OneVsRestClassifier\nfrom sklearn.multiclass import OneVsOneClassifier\n\niCount = 0\nfor i in range(100, 140, 40):\n    print(\"i = \", i)\n    \n    # create grid\n    start_index = 1\n    a = 10\n    N = i#math.sqrt(n)\n    n = N*N#10000\n    modVal = N - start_index + 1\n    celldata = np.zeros((n,), dtype=[('index', 'i4'), ('row', 'i4'),('col', 'i4')])\n    gridcell = pd.DataFrame(celldata)\n\n    print( \"N: \",N )\n\n    cellValuesCombo = np.asarray(list(itertools.product(range(1, int(N)+1),range(1, int(N)+1))))\n    gridcell['row'] = cellValuesCombo[:,0]\n    gridcell['col'] = cellValuesCombo[:,1]\n    gridcell['index'] = gridcell['row'] + (modVal*gridcell['col'])\n\n    dta['gridcell_x'] = (dta['x']*N/a) + 1\n    dta['gridcell_y'] = (dta['y']*N/a) + 1\n    dta['gridcell_index'] = dta['gridcell_x'] + (modVal*dta['gridcell_y'])\n\n    #-- Filter data\n    xy = dta[dta['gridcell_index'] == gridcell.iloc[0,0]]\n    \n    \"\"\"\n    xy['hour'] = (dta['time'] / 60) % 24\n    xy['weekday'] = (dta['time'] / (60*24)) % 7\n    xy['month'] = (dta['time'] / (60*24*30)) % 12\n    xy['year'] = dta['time'] / (60*24*365)\n    xy['day'] = (dta['time'] / (60*24)) % 365\n    \"\"\"\n    \n    xy_sub = xy[['x', 'y', 'place_id', 'time', 'accuracy']]\n    vw = xy[['x', 'y']]\n    tu = xy[['x', 'y', 'time']]\n\n    print( \"xy: \",xy.shape )\n    print( \"halfSize: \",halfSize )\n    print( dta[:5] )\n\n\n    #-- reduce dimensionality of features\n    from sklearn.decomposition import PCA\n    from sklearn.preprocessing import StandardScaler\n    \n    #-- plotting x against y with colors for each place\n    temp_x = iCount % halfSize if (halfSize>0) else 0 #remainder\n    temp_y = iCount / halfSize if (halfSize>0) else 0 #quotient\n    #axarr[temp_x, temp_y].scatter(xy['x'], xy['y'], xy['time'], c=xy['place_id'], linewidth=0.0)#\n    iCount = iCount+1\n    \n    \"\"\"\n    projCount = 220 + iCount\n    print( \"projCount: \",projCount )\n    ax = fig.add_subplot(projCount, projection='3d')\n    ax.scatter(xy['x'], xy['y'], xy['time'], c=xy['place_id'], linewidth=0.0)\n    \"\"\"\n#plt.show()\n\n\n\n"
 }
],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}}, "nbformat": 4, "nbformat_minor": 0}