{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Imports and Data Download","metadata":{}},{"cell_type":"code","source":"import sys\nsys.path.append('/kaggle/input/pip-install-datatable/packages/')\nfrom datatable import dt, f, g, sort, join, by\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n!wget --content-disposition https://www.kaggle.com/competitions/41875/leaderboard/download/public\n# !wget --content-disposition https://www.kaggle.com/competitions/52784/leaderboard/download/private\nDT_public = dt.fread(\"*public*.zip\")\n# DT_private = dt.fread(\"*private*.zip\")","metadata":{"execution":{"iopub.status.busy":"2023-08-22T00:08:57.661685Z","iopub.execute_input":"2023-08-22T00:08:57.662317Z","iopub.status.idle":"2023-08-22T00:09:00.366409Z","shell.execute_reply.started":"2023-08-22T00:08:57.662284Z","shell.execute_reply":"2023-08-22T00:09:00.365116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Some Statistics","metadata":{}},{"cell_type":"code","source":"teams_total = DT_public.nrows\nteams_multi = DT_public[:, dt.re.match(f.TeamMemberUserNames, \".*,.*\")].sum1()\nteams_solo = teams_total - teams_multi\nsubs_firstlast = DT_public[:, f.LastSubmissionDate, dt.sort(f.LastSubmissionDate)][[0, -1], :].to_list()\nsubs_total = DT_public[\"SubmissionCount\"].sum1()\nsubs_min = DT_public[\"SubmissionCount\"].min1()\nsubs_max = DT_public[\"SubmissionCount\"].max1()\nsubs_median = DT_public[:, dt.int8(dt.median(f.SubmissionCount))][0, 0]\n\nprint(f\"Number of teams: {teams_total:,} ({teams_solo:,} solo/{teams_multi:,} multi)\")\nprint(f\"Number of submissions: {subs_total:,}\") \nprint(f\"First submission: {subs_firstlast[0][0]}\")\nprint(f\"Last submission: {subs_firstlast[0][1]}\")\nprint(f\"Submissions per team: {subs_min}/{subs_max}/{subs_median} (min/max/median)\")\n\nlbs = {\"Public\" : DT_public, \n       #\"Private\" : DT_private\n      }\n\nfor lb_type, DT in lbs.items():\n    score_min = DT[\"Score\"].min1()\n    score_max = DT[\"Score\"].max1()\n    score_median = DT[:, dt.median(f.Score)][0, 0]\n    print(f\"{lb_type} LB scores: {score_min}/{score_max}/{score_median} (min/max/median)\")\n    print()","metadata":{"execution":{"iopub.status.busy":"2023-08-22T00:09:08.555594Z","iopub.execute_input":"2023-08-22T00:09:08.556067Z","iopub.status.idle":"2023-08-22T00:09:08.603009Z","shell.execute_reply.started":"2023-08-22T00:09:08.556025Z","shell.execute_reply":"2023-08-22T00:09:08.601993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Public LB Medal Thresholds","metadata":{}},{"cell_type":"code","source":"DT_scores = DT_public[:, :, by(-f.Score)]\n\npos_bronze = int(teams_total * 0.1)\npos_silver = int(teams_total * 0.05)\npos_gold = int(10 + 0.002 * teams_total)\n\nscore_bronze = DT_scores[pos_bronze - 1, \"Score\"]\nscore_silver = DT_scores[pos_silver - 1, \"Score\"]\nscore_gold = DT_scores[pos_gold - 1, \"Score\"]\n\nprint(f\"In bronze: {pos_bronze - pos_silver} teams starting at {score_bronze}\")\nprint(f\"In silver: {pos_silver - pos_gold} teams starting at {score_silver}\")\nprint(f\"In gold  : {pos_gold} teams starting at {score_gold}\")","metadata":{"execution":{"iopub.status.busy":"2023-08-22T00:09:16.571413Z","iopub.execute_input":"2023-08-22T00:09:16.571824Z","iopub.status.idle":"2023-08-22T00:09:16.582238Z","shell.execute_reply.started":"2023-08-22T00:09:16.571788Z","shell.execute_reply":"2023-08-22T00:09:16.580665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Public LB Scores vs Number of Teams","metadata":{}},{"cell_type":"code","source":"DT_grp = DT_public[:, dt.count(), by(f.Score)]\nscore, nteams = DT_grp[:, dt.first(f[:]), sort(-f.count)].to_list()\nprint(f\"Most frequent public score: {score[0]} by {nteams[0]:,} teams\")\nprint()\n\nlb = DT_grp[f.Score > 0.3, :].to_list()\nplt.bar(lb[0], lb[1], color ='tab:blue', width = 0.003)\nplt.xlabel(f\"Public LB Score\")\nplt.ylabel(\"Number of Teams, Log Scale\")\nplt.xticks(np.arange(0.3, 0.7, 0.05))\nplt.yscale(\"log\")\nplt.title(f\"Public scores > 0.3 and bronze/silver/gold thresholds\")\nplt.axvline(x=score_gold, color='orange', linewidth=0.5)\nplt.axvline(x=score_silver, color='grey', linewidth=0.5)\nplt.axvline(x=score_bronze, color='brown', linewidth=0.5)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-22T00:09:22.847418Z","iopub.execute_input":"2023-08-22T00:09:22.847861Z","iopub.status.idle":"2023-08-22T00:09:24.966141Z","shell.execute_reply.started":"2023-08-22T00:09:22.847828Z","shell.execute_reply":"2023-08-22T00:09:24.964851Z"},"trusted":true},"execution_count":null,"outputs":[]}]}