{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "679f266d-e4d2-bcf9-abe1-e173caf96727"
      },
      "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",
        "\n",
        "import numpy as np # linear algebra\n",
        "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
        "import ml_metrics as metrics\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",
        "\n",
        "from subprocess import check_output\n",
        "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n",
        "\n",
        "# Any results you write to the current directory are saved as output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "829b6610-eb43-26ea-65ca-4a93d65d32df"
      },
      "outputs": [],
      "source": [
        "!head -n1 ../input/train.csv > ../working/sampletrain.csv\n",
        "!shuf -n 10000 ../input/train.csv >> ../working/sampletrain.csv"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "73cddc0e-1f71-e239-9dfc-5dbd118156c7"
      },
      "outputs": [],
      "source": [
        "train=pd.read_csv('../working/sampletrain.csv')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "58afbdb0-879e-3bcc-6e49-8e89882b9a59"
      },
      "outputs": [],
      "source": [
        "train.shape"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a8cd4869-6b0d-cfc1-bd35-ead495815a41"
      },
      "outputs": [],
      "source": [
        "train[\"date_time\"] = pd.to_datetime(train[\"date_time\"])\n",
        "train[\"year\"] = train[\"date_time\"].dt.year\n",
        "train[\"month\"] = train[\"date_time\"].dt.month"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "d10c53c0-5005-526a-5c89-23ec9bad5405"
      },
      "outputs": [],
      "source": [
        "t1 = train[((train.year == 2013) | ((train.year == 2014) & (train.month < 8)))]\n",
        "t2 = train[((train.year == 2014) & (train.month >= 8))]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "bcad3004-f176-5530-b250-d4de07e7e925"
      },
      "outputs": [],
      "source": [
        "t2 = t2[t2.is_booking == True]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "05c040fb-9481-72d2-17de-ff623da55ca4"
      },
      "outputs": [],
      "source": [
        "most_common_clusters = list(train.hotel_cluster.value_counts().head().index)\n",
        "predictions = [most_common_clusters for i in range(t2.shape[0])]\n",
        "target = [[l] for l in t2[\"hotel_cluster\"]]\n",
        "metrics.mapk(target, predictions, k=5)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "59f3e9fd-6a74-9c50-3452-0061f43ce627"
      },
      "outputs": [],
      "source": [
        ""
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}