{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "4203e3e6-3d2c-2706-b733-6911180df3fd"
      },
      "outputs": [],
      "source": [
        "library(readr) # CSV file I/O, e.g. the read_csv function\n",
        "library(dplyr)\n",
        "library(data.table)\n",
        "library(tidyr)\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "2deb583c-01cc-0cda-259b-5e5f074c3b26"
      },
      "outputs": [],
      "source": [
        "# Read in some rows of data, see how it all comes together\n",
        "\n",
        "#clicks_train <- fread('../input/clicks_train.csv', nrows=20000)\n",
        "documents_categories <- fread('../input/documents_categories.csv')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a87b0a0c-74d1-6add-4d2e-ef2ca7de586b"
      },
      "outputs": [],
      "source": [
        "head(documents_categories)\n",
        "print(paste0('nrows: ', nrow(documents_categories)))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "f893c5af-5a21-05a4-480a-f417a8c7c6da"
      },
      "outputs": [],
      "source": [
        "doc_table = table(documents_categories$document_id)\n",
        "doc_table = doc_table[order(-doc_table)]\n",
        "doc_table[1:20]\n",
        "min(doc_table)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "6ef520fb-870f-88a2-a0d7-56a0c2fd99d2"
      },
      "source": [
        "looks like documents_ids come solo or in pairs"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "6e5d75b9-f231-929a-30c3-6e9297c26404"
      },
      "outputs": [],
      "source": [
        "print(paste0('Solo document_ids:   ', sum(doc_table == 1)))\n",
        "print(paste0('Paired document_ids: ', sum(doc_table == 2)))\n",
        "print(paste0('Ratio of paired to solo: ', round(sum(doc_table == 2)/sum(doc_table == 1),4)))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "072484f6-cd55-9530-61cc-a2818429a545"
      },
      "outputs": [],
      "source": [
        "# Is the sum of confidence level for every pair/solo approximately 1?\n",
        "paste0('Mean Confidence Level : ', round(sum(documents_categories$confidence_level) / (2652826 + 175823),4))\n",
        "# No it's a bit under, what about by solo vs paired?\n",
        "# Paired\n",
        "paste0('Mean Confidence Level, Paired: ', round(sum(documents_categories$confidence_level[documents_categories$document_id %in% names(doc_table[doc_table == 2])]) / (2652826),4))\n",
        "# Solo\n",
        "paste0('Mean Confidence Level, Solo: ', round(sum(documents_categories$confidence_level[documents_categories$document_id %in% names(doc_table[doc_table == 1])]) / (175823),4))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "fd039360-0767-a098-8d67-8dec6b393676"
      },
      "outputs": [],
      "source": [
        "length(unique(documents_categories$category_id))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "425d7880-7d87-16a7-5289-c3034bbb075d"
      },
      "outputs": [],
      "source": [
        "cat_table = table(documents_categories$category_id)\n",
        "cat_table = cat_table[order(-cat_table)]\n",
        "cat_table\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "a113ae78-066b-f992-61c1-70d8b8a15f5f"
      },
      "outputs": [],
      "source": ""
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "R",
      "language": "R",
      "name": "ir"
    },
    "language_info": {
      "codemirror_mode": "r",
      "file_extension": ".r",
      "mimetype": "text/x-r-source",
      "name": "R",
      "pygments_lexer": "r",
      "version": "3.3.1"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}