Software | Version |
---|
Python | 3.6.8 64bit [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] |
IPython | 7.2.0 |
OS | Darwin 18.2.0 x86_64 i386 64bit |
pandas | 0.23.4 |
Tue Mar 12 21:03:56 2019 PDT |
"
],
"text/latex": [
"\\begin{tabular}{|l|l|}\\hline\n",
"{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n",
"Python & 3.6.8 64bit [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE\\_401/final)] \\\\ \\hline\n",
"IPython & 7.2.0 \\\\ \\hline\n",
"OS & Darwin 18.2.0 x86\\_64 i386 64bit \\\\ \\hline\n",
"pandas & 0.23.4 \\\\ \\hline\n",
"\\hline \\multicolumn{2}{|l|}{Tue Mar 12 21:03:56 2019 PDT} \\\\ \\hline\n",
"\\end{tabular}\n"
],
"text/plain": [
"Software versions\n",
"Python 3.6.8 64bit [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]\n",
"IPython 7.2.0\n",
"OS Darwin 18.2.0 x86_64 i386 64bit\n",
"pandas 0.23.4\n",
"Tue Mar 12 21:03:56 2019 PDT"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%load_ext version_information\n",
"%version_information pandas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Goalie Pull Bayes Optimize\n",
"\n",
" - Exploratory analysis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Explore Parsed Goalie Pull Data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import os\n",
"import re\n",
"import datetime\n",
"import time\n",
"import glob\n",
"from tqdm import tqdm_notebook\n",
"from colorama import Fore, Style"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"\n",
"%config InlineBackend.figure_format='retina'\n",
"sns.set() # Revert to matplotlib defaults\n",
"plt.rcParams['figure.figsize'] = (12, 8)\n",
"plt.rcParams['axes.labelpad'] = 10\n",
"plt.style.use('ggplot')\n",
"\n",
"def savefig(plt, name):\n",
" plt.savefig(f'../../figures/{name}.png', bbox_inches='tight', dpi=300)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[36mcsv\u001b[m\u001b[m/ \u001b[1m\u001b[36mpkl\u001b[m\u001b[m/\n"
]
}
],
"source": [
"ls ../../data/processed/"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20032004_goalie_pulls_2019-03-01.pkl 20062007_goalie_pulls_2019-03-01.pkl\n",
"20052006_goalie_pulls_2019-03-01.pkl\n"
]
}
],
"source": [
"ls ../../data/processed/pkl"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def load_data():\n",
" return pd.concat((\n",
" pd.read_pickle('../../data/processed/pkl/20032004_goalie_pulls_2019-03-01.pkl'),\n",
" pd.read_pickle('../../data/processed/pkl/20052006_goalie_pulls_2019-03-01.pkl'),\n",
" pd.read_pickle('../../data/processed/pkl/20062007_goalie_pulls_2019-03-01.pkl'),\n",
"))\n",
"\n",
"def clean_df(df):\n",
" _df = df.copy()\n",
" \n",
" len_0 = _df.shape[0]\n",
" print('Removing goal_for_time < 15 mins')\n",
" _df = _df[~(_df.goal_for_time < datetime.timedelta(seconds=15*60))]\n",
" print(f'Removed {len_0 - _df.shape[0]} total rows')\n",
" \n",
" if 'game_end_time' in df.columns:\n",
" len_0 = _df.shape[0]\n",
" print('Removing game_end_time < 15 mins')\n",
" _df = _df[~(_df.game_end_time < datetime.timedelta(seconds=60*15))]\n",
" print(f'Removed {len_0 - _df.shape[0]} total rows')\n",
" \n",
" return _df"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Removing goal_for_time < 15 mins\n",
"Removed 1 total rows\n"
]
}
],
"source": [
"df = load_data()\n",
"df = clean_df(df)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Label the outcomes\n",
"df['label'] = ''\n",
"label_masks = {\n",
" 'goal_for': ~(df.goal_for_time.isnull()),\n",
" 'goal_against': ~(df.goal_against_time.isnull()),\n",
" 'no_goals': ~(df.game_end_timedelta.isnull()), \n",
"}\n",
"for label, mask in label_masks.items():\n",
" df.loc[mask, 'label'] = label\n",
"df.loc[df.label == '', 'label'] = float('nan')\n",
"df.label.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"