{"cells":[
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages\n# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats\n# For example, here's several helpful packages to load in \n\nlibrary(ggplot2) # Data visualization\nlibrary(readr) # CSV file I/O, e.g. the read_csv function\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\nsystem(\"ls ../input\")\n\n# Any results you write to the current directory are saved as output.\n\nlibrary(data.table)\nlibrary(bit64)\n\ntrain_full <- fread(\"../input/train.csv\")\nsetkey(train_full, time, place_id)\n\ntrain_n_time <- train_n_time <- train_full[,.N, by=\"time\"]\ntrain_n_time <- train_n_time[,c(\"Hour\",\"Day\"):=list(floor(time/60), floor(time/60/24))]\ntrain_n_day <- train_n_time[,list(N=sum(N), time_start=min(time), time_end=max(time)), by=\"Day\"]\ntrain_n_day[,plot(.SD[,list(Day, N)], type=\"l\")]\n"
 },
 {
  "cell_type": "markdown",
  "metadata": {},
  "source": "# Time interval\n- based on the idea that data are on minutes; good support for this elsewhere\n\n# Features\n- N can be affected by changes in visits per place, or changes in the number of places\n- Overall positive trend\n- Weekly (?) cycle\n- 2 large drops\n- 1 small drop\n\n# Features of drops (eyeballing)\n- First drop is largest, lasts > 3 weeks\n- Second drop is about as big, but a little shorter\n- Third drop is ~1/4 size of others, more gradual, doesn't have a clearly-sustained trough\n- The initial rate of increase for the drops isn't the same; 1st drop happens more slowly than second; third drop very gradual\n\n# My guess\nI think the drops are based on common features of the academic calendar. Every (?American?) school child knows there are 3 big breaks during the school year:  \n  \n  1. summer break  \n  2. winter break  \n  3. spring break\n\nI see some flaws with this idea, but let me first point out some strengths. First, the abruptness of the 3 drops loosely corresponds to my expectations of the synchrony of the onset of these breaks among academic institutions.\n\n- Summer break starts and end at slightly different times, but it's long enough that it overlaps for most people.   \n- Winter break has less variance in its start and end date, on avergae, because of various religious/ national holidays entraining the timing of the break  \n- Spring break has always seemed to be the least synchronous of the three breaks. It's also short. That's probably why it slowly goes down, and doesn't remain at a minimum for long.\n\nWhy do I think this hypothesis is incorrect? The spread between these events is quite right for it to be the academic breaks. There's really only 8 full weeks between the first two drops. That's enough for maybe a quarter. So perhaps a spring break to summer break transition, but then that's a very short summer break.\n\nFurthermore, and perhaps more concerning (to me), is that the events don't seem to occur on an annual cycle. The middle of the first drop is near day 180, and the time series ends ~1 yr after that. If these are annual events, and if the units of the original data are in minutes, we should be seeing the start of the first big drop at the end of this series.\n\nSo this is pretty inconclusive, but maybe it'll get others' 'wheels' turning. It might also be possible that the addition or removal of `place_id`'s is obscuring a more regular process.\n"
 }
],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"}}, "nbformat": 4, "nbformat_minor": 0}