{"cells": [{"cell_type": "code", "execution_count": 1, "metadata": {"_kg_hide-input": true}, "outputs": [], "source": ["# Auto-generated, do not edit!\n", "# One final run.\n", "INIT = [('artgor/march-madness-2020-ncaam-eda-and-baseline',\n", "  'march-madness-2020-ncaam-eda-and-baseline',\n", "  7982339,\n", "  'March Madness 2020 NCAAM EDA and baseline',\n", "  '2020-03-05T09:29:41.637Z',\n", "  'Andrew Lukyanenko',\n", "  'artgor',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/727004-gr.jpg',\n", "  0.38446,\n", "  90,\n", "  '\ud83e\udd47'),\n", " ('ratan123/march-madness-2020-ncaam-simple-lightgbm-on-kfold',\n", "  'march-madness-2020-ncaam-simple-lightgbm-on-kfold',\n", "  7985375,\n", "  'March Madness 2020 NCAAM:Simple Lightgbm on KFold',\n", "  '2020-03-06T15:31:46.44Z',\n", "  'ratan rohith',\n", "  'ratan123',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1649622-kg.png',\n", "  0.14907,\n", "  68,\n", "  '\ud83e\udd47'),\n", " ('vbmokin/mm-ncaam-no-leaks-lgb-xgb-logreg',\n", "  'mm-ncaam-no-leaks-lgb-xgb-logreg',\n", "  8053294,\n", "  'MM NCAAM [No leaks]: LGB, XGB, LogReg',\n", "  '2020-03-13T13:14:34.803Z',\n", "  'Vitalii Mokin',\n", "  'vbmokin',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1798416-gp.jpg',\n", "  0.04872,\n", "  63,\n", "  '\ud83e\udd48'),\n", " ('khoongweihao/ncaam2020-xgboost-lightgbm-k-fold-baseline',\n", "  'ncaam2020-xgboost-lightgbm-k-fold-baseline',\n", "  7990667,\n", "  'NCAAM2020: XGBoost + LightGBM K-Fold (Baseline)',\n", "  '2020-02-25T05:01:27.193Z',\n", "  'Wei Hao Khoong',\n", "  'khoongweihao',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1738095-kg.png',\n", "  0.03966,\n", "  44,\n", "  '\ud83e\udd48'),\n", " ('hiromoon166/2020-basic-starter-kernel',\n", "  '2020-basic-starter-kernel',\n", "  7979510,\n", "  '2020 Basic Starter Kernel',\n", "  '2020-02-15T09:17:12.803Z',\n", "  'hiromu',\n", "  'hiromoon166',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1497263-kg.jpg',\n", "  0.54999,\n", "  35,\n", "  '\ud83e\udd48'),\n", " ('latimerb/2020-model-comparison-no-leak-submission',\n", "  '2020-model-comparison-no-leak-submission',\n", "  8034043,\n", "  '2020 Model Comparison + No leak submission',\n", "  '2020-02-24T19:34:47.517Z',\n", "  'BenLatimer',\n", "  'latimerb',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1265370-fb.jpg',\n", "  0.47433,\n", "  21,\n", "  '\ud83e\udd49'),\n", " ('nxrprime/march-madness-2020-ncaam-simple-lightgbm-on-kfold',\n", "  'march-madness-2020-ncaam-simple-lightgbm-on-kfold',\n", "  7990996,\n", "  'March Madness 2020 NCAAM:Simple Lightgbm on KFold',\n", "  '2020-02-16T04:58:19.02Z',\n", "  'Pentagram',\n", "  'nxrprime',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/4321234-kg.jpg',\n", "  0.35928,\n", "  12,\n", "  '\ud83e\udd49'),\n", " ('takaishikawa/no-ml-modeling-ncaam2020',\n", "  'no-ml-modeling-ncaam2020',\n", "  8100893,\n", "  'No ML Modeling - NCAAM2020',\n", "  '2020-02-24T02:39:18.213Z',\n", "  'Tak',\n", "  'takaishikawa',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1015481-kg.jpg',\n", "  0.56364,\n", "  11,\n", "  '\ud83e\udd49'),\n", " ('miklgr500/keras-nn',\n", "  'keras-nn',\n", "  8009038,\n", "  'Keras NN',\n", "  '2020-02-23T12:01:38.517Z',\n", "  'Michael Kazachok',\n", "  'miklgr500',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1210896-kg.jpg',\n", "  0.47433,\n", "  11,\n", "  '\ud83e\udd49'),\n", " ('chariots17/predicting-with-dnn-xgboost-tensorflow',\n", "  'predicting-with-dnn-xgboost-tensorflow',\n", "  7994061,\n", "  'Predicting with DNN&XGboost(Tensorflow)',\n", "  '2020-02-22T03:49:04.807Z',\n", "  '\u8c01\u4e0d\u91cd\u8981',\n", "  'chariots17',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/2519363-kg.jpg',\n", "  0.35718,\n", "  11,\n", "  '\ud83e\udd49'),\n", " ('code1110/ncaam20-finally-no-leak-starter',\n", "  'ncaam20-finally-no-leak-starter',\n", "  8085813,\n", "  '[NCAAM20] (finally) no-leak starter',\n", "  '2020-02-29T09:57:51.853Z',\n", "  'katsu1110',\n", "  'code1110',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/590240-fb.jpg',\n", "  0.55398,\n", "  9,\n", "  '\ud83e\udd49'),\n", " ('kmatsuyama/to-avoid-overfitting-ensemble-with-trueskill',\n", "  'to-avoid-overfitting-ensemble-with-trueskill',\n", "  8179034,\n", "  'To avoid overfitting: ensemble with TrueSkill ',\n", "  '2020-03-07T02:39:41.377Z',\n", "  'kmatsuyama',\n", "  'kmatsuyama',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/3526234-kg.png',\n", "  0.3763,\n", "  8,\n", "  '\ud83e\udd49'),\n", " ('ash16win/march-madness-ensemble-h2o-xgboost-and-gbm',\n", "  'march-madness-ensemble-h2o-xgboost-and-gbm',\n", "  8158539,\n", "  'March Madness Ensemble H2o-XGBoost and GBM',\n", "  '2020-02-28T20:32:44.443Z',\n", "  'ash16win',\n", "  'ash16win',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/default-thumb.png',\n", "  0.01676,\n", "  7,\n", "  '\ud83e\udd49'),\n", " ('christoffer/simple-k-optimized-elo-model',\n", "  'simple-k-optimized-elo-model',\n", "  8166252,\n", "  'Simple k-optimized Elo model',\n", "  '2020-02-27T14:52:52.227Z',\n", "  'Christoffer Karlsson',\n", "  'christoffer',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/94532-kg.png',\n", "  0.60263,\n", "  6,\n", "  '\ud83e\udd49'),\n", " ('tovvelie/simple-seed-based-model',\n", "  'simple-seed-based-model',\n", "  8071879,\n", "  'Simple seed based model',\n", "  '2020-02-24T10:59:59.62Z',\n", "  'Artem Rumyantsev',\n", "  'tovvelie',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/default-thumb.png',\n", "  0.59323,\n", "  5,\n", "  ' '),\n", " ('santohide/my-first-gbdt',\n", "  'my-first-gbdt',\n", "  8187632,\n", "  'My first GBDT ',\n", "  '2020-03-11T12:24:14.853Z',\n", "  'santo',\n", "  'santohide',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/default-thumb.png',\n", "  0.43304,\n", "  5,\n", "  ' '),\n", " ('domoldo/ncaa-logistic-regression-example-gmu-kaggle-club',\n", "  'ncaa-logistic-regression-example-gmu-kaggle-club',\n", "  8181864,\n", "  'NCAA Logistic Regression example (GMU Kaggle Club)',\n", "  '2020-02-29T18:37:15.41Z',\n", "  'Dominic White',\n", "  'domoldo',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/31963-kg.jpg',\n", "  0.55256,\n", "  4,\n", "  ' '),\n", " ('code1110/ncaam20-eda-and-nn-lgb-catb-starter',\n", "  'ncaam20-eda-and-nn-lgb-catb-starter',\n", "  7993081,\n", "  '[NCAAM20] EDA and NN+LGB+CatB starter',\n", "  '2020-02-21T13:17:40.517Z',\n", "  'katsu1110',\n", "  'code1110',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/590240-fb.jpg',\n", "  0.32227,\n", "  4,\n", "  ' '),\n", " ('tenffe/autogluon-for-basic-data-process',\n", "  'autogluon-for-basic-data-process',\n", "  7983412,\n", "  'autogluon_for_basic_data_process',\n", "  '2020-02-16T08:49:24.887Z',\n", "  'zhangxin',\n", "  'tenffe',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1536982-kg.jpg',\n", "  0.52281,\n", "  4,\n", "  ' '),\n", " ('jollibobert/ncaam2020-logistic-regression-baseline-cv-0-55',\n", "  'ncaam2020-logistic-regression-baseline-cv-0-55',\n", "  8121881,\n", "  'NCAAM2020 - Logistic Regression Baseline [CV 0.55]',\n", "  '2020-02-26T14:24:26.727Z',\n", "  'Robert Tacbad',\n", "  'jollibobert',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/749307-kg.jpg',\n", "  0.54935,\n", "  3,\n", "  ' '),\n", " ('ben519/professor-data-cleaning-and-modeling',\n", "  'professor-data-cleaning-and-modeling',\n", "  8356503,\n", "  'Professor: Data cleaning and modeling',\n", "  '2020-03-12T15:23:28.177Z',\n", "  'Ben Gorman',\n", "  'ben519',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/112010-kg.jpg',\n", "  0.53676,\n", "  2,\n", "  ' '),\n", " ('adarshsng/march-madness-2020-ncaam-simple-dnn-with-sk-fold',\n", "  'march-madness-2020-ncaam-simple-dnn-with-sk-fold',\n", "  8292317,\n", "  'March Madness 2020 NCAAM: Simple DNN with SK-Fold',\n", "  '2020-03-07T18:33:39.06Z',\n", "  'xdarshsingh',\n", "  'adarshsng',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/3974712-kg.jpeg',\n", "  0.54324,\n", "  2,\n", "  ' '),\n", " ('lorenzodenisi/ncaam-prediction-with-overall-rankings-and-dnn',\n", "  'ncaam-prediction-with-overall-rankings-and-dnn',\n", "  8221058,\n", "  'NCAAM prediction with overall rankings and DNN',\n", "  '2020-03-02T18:41:33.233Z',\n", "  'Lorenzo De Nisi',\n", "  'lorenzodenisi',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/3695984-kg.png',\n", "  0.54715,\n", "  2,\n", "  ' '),\n", " ('scirpus/mother-of-all-gp',\n", "  'mother-of-all-gp',\n", "  8165286,\n", "  'Mother of all GP',\n", "  '2020-02-27T13:50:42.033Z',\n", "  'Scirpus',\n", "  'scirpus',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/241438-fb.jpg',\n", "  0.52124,\n", "  2,\n", "  ' '),\n", " ('scirpus/complex-secret-sauce',\n", "  'complex-secret-sauce',\n", "  8164177,\n", "  'Complex Secret Sauce?',\n", "  '2020-02-27T12:18:21.367Z',\n", "  'Scirpus',\n", "  'scirpus',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/241438-fb.jpg',\n", "  0.51832,\n", "  2,\n", "  ' '),\n", " ('scirpus/secret-sauce',\n", "  'secret-sauce',\n", "  8162934,\n", "  'Secret Sauce?',\n", "  '2020-02-27T10:55:06.26Z',\n", "  'Scirpus',\n", "  'scirpus',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/241438-fb.jpg',\n", "  0.52299,\n", "  2,\n", "  ' '),\n", " ('jarnel/clipping-spline-experiment-on-test-predictions',\n", "  'clipping-spline-experiment-on-test-predictions',\n", "  8067852,\n", "  'Clipping/Spline Experiment on test predictions',\n", "  '2020-02-21T00:00:24.07Z',\n", "  'jarnel',\n", "  'jarnel',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/default-thumb.png',\n", "  0.30627,\n", "  2,\n", "  ' '),\n", " ('ricardo13/ncaam2020-baseline-with-xgb-lgb-blending',\n", "  'ncaam2020-baseline-with-xgb-lgb-blending',\n", "  7990151,\n", "  'NCAAM2020-baseline with XGB&LGB Blending',\n", "  '2020-02-16T01:56:32.217Z',\n", "  'Ricardo Lee',\n", "  'ricardo13',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1110110-kg.jpg',\n", "  0.43584,\n", "  2,\n", "  ' '),\n", " ('omarrodriguez/seed-only-model',\n", "  'seed-only-model',\n", "  8355729,\n", "  'Seed-only model',\n", "  '2020-03-11T19:09:13Z',\n", "  'Omar',\n", "  'omarrodriguez',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/default-thumb.png',\n", "  0.55006,\n", "  1,\n", "  ' '),\n", " ('bsherman10/ncaa-march-madness-2020',\n", "  'ncaa-march-madness-2020',\n", "  8210356,\n", "  'NCAA March Madness 2020',\n", "  '2020-03-10T04:09:34.577Z',\n", "  'Brad Sherman',\n", "  'bsherman10',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1677587-gp.jpg',\n", "  0.51876,\n", "  1,\n", "  ' '),\n", " ('nickteim/google-cloud-simple-model',\n", "  'google-cloud-simple-model',\n", "  8326241,\n", "  'Google cloud simple model ',\n", "  '2020-03-09T23:42:36.14Z',\n", "  'NickTeim',\n", "  'nickteim',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/3766931-kg.PNG',\n", "  0.51801,\n", "  1,\n", "  ' '),\n", " ('miklgr500/bayesian-neural-network-in-keras-ncaam',\n", "  'bayesian-neural-network-in-keras-ncaam',\n", "  8303223,\n", "  'Bayesian Neural Network in Keras NCAAM',\n", "  '2020-03-09T11:20:58.957Z',\n", "  'Michael Kazachok',\n", "  'miklgr500',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1210896-kg.jpg',\n", "  0.59552,\n", "  1,\n", "  ' '),\n", " ('tnmasui/ncaam-2020-lgb-w-fe-on-three-datasets',\n", "  'ncaam-2020-lgb-w-fe-on-three-datasets',\n", "  8210334,\n", "  'NCAAM 2020 - LGB w/ FE on three Datasets',\n", "  '2020-03-02T01:59:12.927Z',\n", "  'Tomonori Masui',\n", "  'tnmasui',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/427399-kg.JPG',\n", "  0.51968,\n", "  1,\n", "  ' '),\n", " ('scirpus/not-another-genetic-program',\n", "  'not-another-genetic-program',\n", "  8132612,\n", "  'Not another Genetic Program',\n", "  '2020-02-25T12:22:54.883Z',\n", "  'Scirpus',\n", "  'scirpus',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/241438-fb.jpg',\n", "  0.61137,\n", "  1,\n", "  ' '),\n", " ('jmaslek/mens-tourney-highest-seed-baseline',\n", "  'mens-tourney-highest-seed-baseline',\n", "  8062442,\n", "  'Mens Tourney - Highest Seed Baseline',\n", "  '2020-02-20T16:01:18.873Z',\n", "  'GoSabres',\n", "  'jmaslek',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1716008-gp.jpg',\n", "  9.44076,\n", "  1,\n", "  ' '),\n", " ('grapestone5321/ml-competition-2020-ncaam-sample-submission',\n", "  'ml-competition-2020-ncaam-sample-submission',\n", "  8340156,\n", "  ' ML Competition 2020-NCAAM-sample_submission',\n", "  '2020-03-10T18:10:38.953Z',\n", "  'Naruhiko Nakanishi',\n", "  'grapestone5321',\n", "  'https://storage.googleapis.com/kaggle-avatars/thumbnails/1107630-kg.jpg',\n", "  0.69314,\n", "  0,\n", "  ' ')]\n"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# Blend NCAAM with 2020 Vision\n", "\n", "Yes, this Notebook will blend all the public stage 1 solutions!\n", "\n", "Along the way, I will plot all their predictions in a 2D histogram (a heatmap), one for each year. (Which is, I hope you realise, the real purpose of this Notebook!) There are links to the actual Notebooks &mdash; so open them up &mdash; this gives you another reason to upvote them: marks for aesthetics :)\n", "\n", "For stage 1 only 63 values per year are used as the ground truth, making it very easy to overfit. What is lurking behind these leaderboard scores? I'm not going to comment on individual entries, but it is easy to see when submissions have a high *noise* level, deviating wildly from the team seeds. Submissions used are from the last run of each source Notebook and some will be *work in progress*.\n", "\n", "See [here](https://www.kaggle.com/jtrotman/meta-march-mania) for a summary of the history of the March Madness Kaggle competitions, including histograms of actual scores after stage 2.\n", "\n", "## Plot Format\n", "\n", "The plot format is introduced [here](https://www.kaggle.com/c/march-machine-learning-mania-2017/discussion/30333).\n", "\n", "To recap: it is easiest to read the row for each team, where white means 50:50, red indicates probably winning, blue means probably losing, the deeper the color, the stronger the probability.\n", "\n", "In this Notebook the play-in matches are removed, leaving a 64x64 grid showing the four 16x16 regions, and all possible tournament matches. Note we only supply half of the grid in submissions: the other half is $1 - Pred$.\n", "\n", "\n", "## More Submission Heatmaps\n", "\n", "In previous years, Kaggle released **all** the stage 2 submission files before the action started: here they all are, **over 2,000 plots**, rendered in the same heatmap format :D\n", "\n", " - [2015](https://www.kaggle.com/jtrotman/beautiful-mania-2015)\n", " - [2016](https://www.kaggle.com/jtrotman/beautiful-mania-2016)\n", " - [2017](https://www.kaggle.com/jtrotman/beautiful-mania-2017)\n"]}, {"cell_type": "code", "execution_count": 2, "metadata": {"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "_kg_hide-input": true, "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5"}, "outputs": [], "source": ["%matplotlib inline\n", "import pandas as pd\n", "import numpy as np\n", "import os, re, sys\n", "import matplotlib.pyplot as plt\n", "from IPython.core.display import HTML, Image\n", "\n", "TAG = 'NCAAM_2020'\n", "DIR  = '../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1'\n", "PNG_DIR = '/kaggle/plots'\n", "OUTPUT_ZIP = f'{TAG}_stage1_plots.zip'\n", "\n", "os.makedirs(PNG_DIR, exist_ok=True)\n", "\n", "def read_results():\n", "    res = pd.read_csv(f'{DIR}/MNCAATourneyCompactResults.csv').query('DayNum>=136')\n", "    TC = ['WTeamID', 'LTeamID']\n", "    res['Low'] = res[TC].min(1)\n", "    res['High'] = res[TC].max(1)\n", "    res['Truth'] = res.eval('Low==WTeamID').astype(int)\n", "    res['Key'] = res.apply(lambda r: f'{r.Season}_{r.Low}_{r.High}', 1)\n", "    res = res.set_index('Key')\n", "    return res\n", "\n", "TEAMS = pd.read_csv(f'{DIR}/MTeams.csv', index_col=0)\n", "SEEDS = pd.read_csv(f'{DIR}/MNCAATourneySeeds.csv', index_col=2)\n", "RESULTS = read_results()\n", "\n", "TEAMS.shape, SEEDS.shape, RESULTS.shape"]}, {"cell_type": "code", "execution_count": 3, "metadata": {"_kg_hide-input": true}, "outputs": [], "source": ["plt.rc('figure', figsize=(14, 14))\n", "plt.rc('font', size=12)\n", "\n", "ICOLS = ['i1', 'i2']\n", "\n", "\n", "def expand_sub(df):\n", "    parts = df['id'].str.split('_')\n", "    df['year'] = parts.str[0].astype(int)\n", "    df['t1'] = parts.str[1].astype(int)\n", "    df['t2'] = parts.str[2].astype(int)\n", "    return df[['id', 'year', 't1', 't2', 'pred']].set_index('id')\n", "\n", "\n", "# return a submission in a standard form\n", "def read_sub(name):\n", "    df = pd.read_csv(name)\n", "    df.columns = df.columns.str.lower()\n", "    return expand_sub(df)\n", "\n", "\n", "def log_loss(df):\n", "    p = np.where(df.Truth, df.pred, 1 - df.pred)\n", "    # clip low predictions to avoid infinite loss\n", "    p = p.clip(min=1e-15)\n", "    return (-np.log(p)).mean()\n", "\n", "\n", "def score_sub(sub):\n", "    df = sub.join(RESULTS, how='inner')\n", "    return log_loss(df)\n", "\n", "\n", "class Year:\n", "\n", "    def __init__(self, res, seeds):\n", "        self.res = res\n", "        ids = set(res.Low) | set(res.High)\n", "        self.nteams = len(ids)\n", "        self.seeds = seeds[seeds.index.isin(ids)] # 64 teams\n", "        self.seeds = self.seeds.join(TEAMS)\n", "        self.inds = dict(zip(self.seeds.index, range(self.nteams)))\n", "        # labels for each axis\n", "        self.seeds['lx'] = self.seeds.Seed + \" \" + self.seeds.TeamName\n", "        self.seeds['ly'] = self.seeds.TeamName + \" \" + self.seeds.Seed\n", "    \n", "    def add_inds(self, df):\n", "        df = df.assign(i1=df.t1.map(self.inds), i2=df.t2.map(self.inds))\n", "        df = df.dropna()\n", "        df[ICOLS] = df[ICOLS].astype(int)\n", "        return df\n", "\n", "    def to_matrix(self, sub):\n", "        sub = self.add_inds(sub)\n", "        nteams = self.nteams\n", "        m = np.ones((nteams, nteams)) * 0.5\n", "        m[sub.i1, sub.i2] = sub.pred\n", "        m[sub.i2, sub.i1] = 1 - sub.pred\n", "        return m\n", "\n", "    def heatmap(self, sub, filename, cmap=plt.cm.seismic):\n", "        probs = self.to_matrix(sub)\n", "        fig, ax = plt.subplots()\n", "        heatmap = ax.pcolormesh(probs, vmin=0., vmax=1., cmap=cmap)\n", "\n", "        ax.spines['top'].set_visible(False)\n", "        ax.spines['right'].set_visible(False)\n", "        ax.spines['bottom'].set_visible(False)\n", "        ax.spines['left'].set_visible(False)\n", "\n", "        ax.invert_yaxis()\n", "        ax.tick_params(direction='out')\n", "        ax.xaxis.tick_top()\n", "        ax.yaxis.tick_left()\n", "        plt.xticks(rotation=90)\n", "\n", "        # put the major ticks at the middle of each cell\n", "        ax.set_xticks(np.arange(self.nteams)+0.5, minor=False)\n", "        ax.set_yticks(np.arange(self.nteams)+0.5, minor=False)\n", "        ax.set_xticklabels(self.seeds['lx'])\n", "        ax.set_yticklabels(self.seeds['ly'])\n", "        plt.savefig(filename, bbox_inches='tight')   \n", "\n", "\n", "YLIST = SEEDS.Season.unique()\n", "YEARS = { year: Year(RESULTS.query(f'Season=={year}'), SEEDS.query(f'Season=={year}')) for year in YLIST }"]}, {"cell_type": "code", "execution_count": 4, "metadata": {"_kg_hide-input": true}, "outputs": [], "source": ["def reader(lst):\n", "    for scriptUrl, currentUrlSlug, *rest in lst:\n", "        bd = f'../input/{currentUrlSlug}'\n", "        subs = {}\n", "        try:\n", "            files = os.listdir(bd)\n", "            for f in files:\n", "                if f.lower().endswith('.csv'):\n", "                    try:\n", "                        sub = read_sub(f'{bd}/{f}')\n", "                        subs[f] = sub\n", "                    except:\n", "                        pass\n", "        except:\n", "            pass\n", "        if len(subs) > 0:\n", "            yield [scriptUrl, currentUrlSlug] + rest + [subs]\n", "\n", "# Ensemble average\n", "sums = 0\n", "count = 0\n", "\n", "def show_years(sub, tag):\n", "    display(HTML(\n", "        f'<h2>Prediction Stats</h2>'\n", "        f'<p>Log Loss: {score_sub(sub):.6f}'\n", "    ))\n", "    gb = sub.groupby('year')\n", "    display(gb.pred.agg(['count', 'min', 'max']))\n", "    for year, subdf in gb:\n", "        display(HTML(\n", "            f'<h2>{year}</h2>'\n", "            f'<p>Log Loss: {score_sub(subdf):.6f}'\n", "        ))\n", "        YEARS[year].heatmap(subdf, f'{PNG_DIR}/{tag}_{year}')\n", "        plt.show()\n", "\n", "for scriptUrl, currentUrlSlug, _id, title, lastRunTime, displayName, userName, thumbnailUrl, bestPublicScore, totalVotes, medal, subs in reader(INIT):\n", "    display(HTML(\n", "        f'<h1 id=\"{currentUrlSlug}\">{title}</h1>'\n", "        f'<table><tr><td style=\"vertical-align:top\"><img src=\"{thumbnailUrl}\"></td>'\n", "        f'<td style=\"vertical-align:top\"><p><b>{displayName}</b>'\n", "        f'<p><a href=\"https://www.kaggle.com/{scriptUrl}\">{scriptUrl}</a>'\n", "        f'<br>Last run: {pd.to_datetime(lastRunTime).strftime(\"%c\")} '\n", "        f'<br>Votes: {totalVotes} {medal}'\n", "        f'<br>Best public log-loss: {bestPublicScore} '\n", "        f'</td></tr></table>'\n", "    ))\n", "    \n", "    for csv, sub in subs.items():\n", "        show_years(sub, f'{userName}_{currentUrlSlug}')\n", "\n", "        sums += sub[['pred']].clip(0, 1)\n", "        count += 1"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# Ensemble\n", "\n", "Compute the mean average of all the submissions we managed to load."]}, {"cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": ["ensemble = (sums / count)\n", "count, score_sub(ensemble)"]}, {"cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": ["show_years(expand_sub(ensemble.reset_index()), f'{TAG}_ensemble')"]}, {"cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": ["ensemble.to_csv(f'{TAG}_blend.csv')"]}, {"cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": ["!7z a -bd -mmt4 {OUTPUT_ZIP} {PNG_DIR}/*.png"]}, {"cell_type": "code", "execution_count": 9, "metadata": {"_kg_hide-input": true}, "outputs": [], "source": ["!find /kaggle > file_list.txt"]}], "metadata": {"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.7.1"}}, "nbformat": 4, "nbformat_minor": 1}