{"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"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":37644,"databundleVersionId":4115646,"sourceType":"competition"}],"dockerImageVersionId":30213,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<img src=\"https://storage.googleapis.com/kaggle-competitions/kaggle/37644/logos/header.png?t=2022-08-05-15-26-16\" width=1500 class=\"center\">\n\n<h1 align=\"center\">🐎 Big Data Derby 2022 Complete EDA 🐎</h1>\n<h2 align=\"center\">Work in progress ⚠️👷🏼</h2>\n            \n<p style=\"padding:20px;\n          color:#9A7D0A;\n          margin:10px;\n          font-size:110%;\n          text-align:center;\n          display:fill;\n          border-radius:10px;\n          border-style: solid;\n          border-color:#9A7D0A;\n          background-color:#FCF3CF;\n          overflow:hidden;\n          font-weight:500\">Welcome to this competition! 👋👋👋</p>\n\n\n<div style=\"padding:20px; \n            color:#633974;\n            margin:10px;\n            font-size:220%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#633974;\n            background-color:#D7BDE2;\n            overflow:hidden;\n            font-weight:500\">Goal</div>\n            \n<p style=\"padding:20px;\n            color:#633974;\n            margin:10px;\n            font-size:110%;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#633974;\n            background-color:#EBDEF0;\n            overflow:hidden;\n            font-weight:500\">\n    The goal of this competition is to analyze horse racing tactics, drafting strategies, and path efficiency. You will develop a model using never before released coordinate data along with basic race information.\n    <br><br>Your work will help racing horse owners, trainers, and veterinarians better understand how equine performance and welfare fit together. With better data analysis, equine welfare could significantly improve.</p>\n\n<div style=\"padding:20px; \n            color:#633974;\n            margin:10px;\n            font-size:220%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#633974;\n            background-color:#D7BDE2;\n            overflow:hidden;\n            font-weight:500\">Context</div>\n\n<p style=\"padding:20px;\n            color:#633974;\n            margin:10px;\n            font-size:110%;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#633974;\n            background-color:#EBDEF0;\n            overflow:hidden;\n            font-weight:500\">Injury prevention is a critical component in modern athletics. Sports that involve animals, such as horse racing, are no different than human sport. Typically, efficiency in movement correlates to both improvements in performance and injury prevention.<br><br>A wealth of data is now collected, including measures for heart rate, EKG, longitudinal movement, dorsal/ventral movement, medial/lateral deviation, total power and total landing vibration. Your data science skills and analysis are needed to decipher what makes the most positive impact.<br><br>In this competition, you will create a model to interpret one aspect of this new data. You’ll be among the first to access X/Y coordinate mapping of horses during races. Using the data, you might analyze jockey decision making, compare race surfaces, or measure the relative importance of drafting. With considerable data, contestants can flex their creativity problem solving skills.<br><br>The New York Racing Association (NYRA) and the New York Thoroughbred Horsemen's Association (NYTHA) conduct world class thoroughbred racing at Aqueduct Racetrack, Belmont Park and Saratoga Race Course.<br><br>With your help, NYRA and NYTHA will better understand their vast data set, which could lead to new ways of racing and training in a highly traditional industry. With improved use of horse tracking data, you could help improve equine welfare, performance and rider decision making.</p>\n\n<div style=\"padding:20px; \n            color:#9A7D0A;\n            margin:10px;\n            font-size:110%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#9A7D0A;\n            background-color:#FCF3CF;\n            overflow:hidden;\n            font-weight:500\">Please leave any suggestions and modifications in the comments!</div>","metadata":{}},{"cell_type":"markdown","source":"### Import libraries","metadata":{}},{"cell_type":"code","source":"import ipywidgets as widgets\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go\nimport os\nimport seaborn as sns\n\n\nfrom datetime import datetime as dt\nfrom IPython.display import display, HTML","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-13T11:35:42.901619Z","iopub.execute_input":"2022-08-13T11:35:42.902215Z","iopub.status.idle":"2022-08-13T11:35:43.648627Z","shell.execute_reply.started":"2022-08-13T11:35:42.902102Z","shell.execute_reply":"2022-08-13T11:35:43.647361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Paths","metadata":{}},{"cell_type":"code","source":"COMPLETE_TABLE = \"../input/big-data-derby-2022/nyra_2019_complete.csv\"\nRACE_TABLE = \"../input/big-data-derby-2022/nyra_race_table.csv\"\nSTART_TABLE = \"../input/big-data-derby-2022/nyra_start_table.csv\"\nTRACKING_TABLE = \"../input/big-data-derby-2022/nyra_tracking_table.csv\"","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:35:43.651266Z","iopub.execute_input":"2022-08-13T11:35:43.651749Z","iopub.status.idle":"2022-08-13T11:35:43.658554Z","shell.execute_reply.started":"2022-08-13T11:35:43.651701Z","shell.execute_reply":"2022-08-13T11:35:43.656935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#616A6B;\n            margin:10px;\n            font-size:220%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #616A6B;\n            background-color:#CCD1D1;\n            overflow:hidden;\n            font-weight:500\">NYRA 2019 Complete</div>\n\n<div style=\"padding:20px; \n            color:#616A6B;\n            margin:10px;\n            font-size:110%;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #616A6B;\n            background-color:#E5E8E8;\n            overflow:hidden;\n            font-weight:500\">This file is the combined 3 files into one table.\n<li>The keys to join them trakus with race - <code style=\"background: grey;\">track_id</code>, <code style=\"background: grey;\">race_date</code>, <code style=\"background: grey;\">race_number</code>.</li>\n\n<li>To join trakus with start - <code style=\"background: grey;\">track_id</code>, <code style=\"background: grey;\">race_date</code>, <code style=\"background: grey;\">race_number</code>, <code style=\"background: grey;\">program_number</code>. \n \n- `track_id` - char(3)\n- `race_date` - date \n- `race_number` - char(3) \n- `program_number` - char(3) \n- `trakus_index` - int \n- `latitude` - float \n- `longitude` - float \n- `distance_id` - int \n- `course_type` - char(1) \n- `track_condition` - char(3) \n- `run_up_distance` - int \n- `race_type` - char(5) \n- `post_time` - char(5) \n- `weight_carried` - int \n- `jockey` - char(50) \n- `odds` - int\n</div>\n","metadata":{}},{"cell_type":"code","source":"nyra_2019_complete = pd.read_csv(COMPLETE_TABLE, sep = ',')\nprint(f\"NYRA Complete table has {nyra_2019_complete.shape[0]} rows and {nyra_2019_complete.shape[1]} columns\")\nnyra_2019_complete.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:35:43.660227Z","iopub.execute_input":"2022-08-13T11:35:43.660650Z","iopub.status.idle":"2022-08-13T11:35:59.658837Z","shell.execute_reply.started":"2022-08-13T11:35:43.660615Z","shell.execute_reply":"2022-08-13T11:35:59.657186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_number = 1\ntrack_id = \"SAR\"\nday = 22\nmonth = 8\nyear = 2019\n\nnyra_2019_complete[\"race_date\"] =  pd.to_datetime(nyra_2019_complete[\"race_date\"], format='%Y-%m-%d')\n\nsubset = nyra_2019_complete[(nyra_2019_complete[\"race_number\"]==race_number) &\n                            (nyra_2019_complete[\"track_id\"]==track_id) &\n                            (nyra_2019_complete[\"race_date\"].dt.month==month) &\n                            (nyra_2019_complete[\"race_date\"].dt.day==day)]\nif len(subset)>5000:\n    subset = subset.sample(5000)\n    \nx = subset[\"longitude\"]\ny = subset[\"latitude\"]\n\n# Layout\nlayout = go.Layout(\n    title = f\"Longitude and Latitude for track id {track_id} race {7} on date {day}/{month}/{year}\",\n    xaxis = dict(\n        title = \"Longitude\"\n    ),\n    yaxis = dict(\n        title = \"Latitude\"\n    )\n\n)\n\nfig = go.Figure(layout=layout)\n\n# Add scatter trace\nfig.add_trace(\n    go.Scatter(\n        mode = \"markers\",\n        x = x,\n        y = y,\n        marker = dict(\n            color = \"yellow\",\n            size = 6,\n            opacity = 0.4,\n            line = dict(color=\"burlywood\", width=1)\n        ),\n        showlegend = False\n    )\n)\n\nfig.update_layout(template=\"plotly_dark\",\n                  title_font_color=\"#FF9300\")\nfig.update_xaxes(title_font_color=\"#FF9300\", # update subplot X label title color\n                tickfont_color=\"#FF9300\") # update subplot X tick color\nfig.update_yaxes(title_font_color=\"#FF9300\", # update subplot X label title color\n                tickfont_color=\"#FF9300\") # update subplot X tick color\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:35:59.661636Z","iopub.execute_input":"2022-08-13T11:35:59.662013Z","iopub.status.idle":"2022-08-13T11:36:03.144103Z","shell.execute_reply.started":"2022-08-13T11:35:59.661982Z","shell.execute_reply":"2022-08-13T11:36:03.142643Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:10px;\n            font-size:220%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Race Table</div>\n\n<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:10px;\n            font-size:110%;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#D6EAF8;\n            overflow:hidden;\n            font-weight:500\">Fields:\n<li><code style=\"background: grey;\">track_id</code> - 3 character id for the track the race took place at. AQU -Aqueduct, BEL - Belmont, SAR - Saratoga.</li>\n<li><code style=\"background: grey;\">race_date</code> - date the race took place. YYYY-MM-DD.</li> \n<li><code style=\"background: grey;\">race_number</code> - Number of the race. Passed as 3 characters but can be cast or converted to int for this data set. </li>\n<li><code style=\"background: grey;\">distance_id</code> - Distance of the race in furlongs passed as an integer. Example - 600 would be 6 furlongs.</li>\n<li><code style=\"background: grey;\">course_type</code> - The course the race was run over passed as one character. M - Hurdle, D - Dirt, O - Outer turf, I - Inner turf, T - turf.</li> \n<li><code style=\"background: grey;\">track_condition</code> - The condition of the course the race was run on passed as three characters. YL - Yielding, FM - Firm, SY - Sloppy, GD - Good, FT - Fast, MY - Muddy, SF - Soft.</li> \n<li><code style=\"background: grey;\">run_up_distance</code> - Distance in feet of the gate to the start of the race passed as an integer.</li> \n<li><code style=\"background: grey;\">race_type</code> - The classification of the race passed as as five characters. STK - Stakes, WCL - Waiver Claiming, WMC - Waiver Maiden Claiming, SST - Starter Stakes, SHP - Starter Handicap, CLM - Claiming, STR - Starter Allowance, AOC - Allowance Optionl Claimer, SOC - Starter Optional Claimer, MCL - Maiden Claiming, ALW - Allowance, MSW - Maiden Special Weight.</li> \n<li><code style=\"background: grey;\">purse</code> - Purse in US dollars of the race passed as an money with two decimal places.</li> \n<li><code style=\"background: grey;\">post_time</code> - Time of day the race began passed as 5 character. Example - 01220 would be 12:20.</li></div>\n","metadata":{}},{"cell_type":"code","source":"race_table = pd.read_csv(RACE_TABLE, sep = ',')\nprint(f\"Race table has {race_table.shape[0]} rows and {race_table.shape[1]} columns\")\nrace_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:03.145327Z","iopub.execute_input":"2022-08-13T11:36:03.145708Z","iopub.status.idle":"2022-08-13T11:36:03.177583Z","shell.execute_reply.started":"2022-08-13T11:36:03.145677Z","shell.execute_reply":"2022-08-13T11:36:03.176249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Basic macro statistics</div>","metadata":{}},{"cell_type":"code","source":"race_table.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:03.179763Z","iopub.execute_input":"2022-08-13T11:36:03.180196Z","iopub.status.idle":"2022-08-13T11:36:03.214953Z","shell.execute_reply.started":"2022-08-13T11:36:03.180157Z","shell.execute_reply":"2022-08-13T11:36:03.213997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Missing values</div>\n\n<p style=\"color: #1B4F72;\">There are no missing values</p>","metadata":{}},{"cell_type":"code","source":"race_table.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:03.216313Z","iopub.execute_input":"2022-08-13T11:36:03.216845Z","iopub.status.idle":"2022-08-13T11:36:03.228543Z","shell.execute_reply.started":"2022-08-13T11:36:03.216813Z","shell.execute_reply":"2022-08-13T11:36:03.226812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Unique values</div>","metadata":{}},{"cell_type":"code","source":"race_table.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:03.231922Z","iopub.execute_input":"2022-08-13T11:36:03.232370Z","iopub.status.idle":"2022-08-13T11:36:03.245346Z","shell.execute_reply.started":"2022-08-13T11:36:03.232334Z","shell.execute_reply":"2022-08-13T11:36:03.244163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Track ID distribution</div>","metadata":{}},{"cell_type":"code","source":"values = race_table[\"track_id\"].value_counts().tolist()\nindex = tuple(race_table[\"track_id\"].value_counts().index.tolist())\nx = race_table[\"track_id\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center')\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Track id distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:03.246806Z","iopub.execute_input":"2022-08-13T11:36:03.247669Z","iopub.status.idle":"2022-08-13T11:36:03.504042Z","shell.execute_reply.started":"2022-08-13T11:36:03.247631Z","shell.execute_reply":"2022-08-13T11:36:03.502370Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Race date distribution</div>\n","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15,8))\nx = race_table[\"race_date\"].value_counts().index.tolist()\nx = np.asarray(x, dtype='datetime64[s]')\ny = race_table[\"race_date\"].value_counts().values.tolist()\nlabels = x\nplt.scatter(x = x, y = y)\n# plt.xticks(x, labels, rotation='vertical')\nplt.xlabel(\"Date the race took place\")\nplt.ylabel(\"Amount\")\nplt.title(\"Race date distribution\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:03.509465Z","iopub.execute_input":"2022-08-13T11:36:03.510242Z","iopub.status.idle":"2022-08-13T11:36:03.797333Z","shell.execute_reply.started":"2022-08-13T11:36:03.510012Z","shell.execute_reply":"2022-08-13T11:36:03.796019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as mpl\n\n# source: https://stackoverflow.com/questions/32485907/matplotlib-and-numpy-create-a-calendar-heatmap\n\nDAYS = ['Sun.', 'Mon.', 'Tues.', 'Wed.', 'Thurs.', 'Fri.', 'Sat.']\nMONTHS = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'June', 'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.']\n\n\ndef date_heatmap(series, start=None, end=None, mean=False, ax=None, **kwargs):\n    '''Plot a calendar heatmap given a datetime series.\n\n    Arguments:\n        series (pd.Series):\n            A series of numeric values with a datetime index. Values occurring\n            on the same day are combined by sum.\n        start (Any):\n            The first day to be considered in the plot. The value can be\n            anything accepted by :func:`pandas.to_datetime`. The default is the\n            earliest date in the data.\n        end (Any):\n            The last day to be considered in the plot. The value can be\n            anything accepted by :func:`pandas.to_datetime`. The default is the\n            latest date in the data.\n        mean (bool):\n            Combine values occurring on the same day by mean instead of sum.\n        ax (matplotlib.Axes or None):\n            The axes on which to draw the heatmap. The default is the current\n            axes in the :module:`~matplotlib.pyplot` API.\n        **kwargs:\n            Forwarded to :meth:`~matplotlib.Axes.pcolormesh` for drawing the\n            heatmap.\n\n    Returns:\n        matplotlib.collections.Axes:\n            The axes on which the heatmap was drawn. This is set as the current\n            axes in the `~matplotlib.pyplot` API.\n    '''\n    # Combine values occurring on the same day.\n    dates = series.index.floor('D')\n    group = series.groupby(dates)\n    series = group.mean() if mean else group.sum()\n\n    # Parse start/end, defaulting to the min/max of the index.\n    start = pd.to_datetime(start or series.index.min())\n    end = pd.to_datetime(end or series.index.max())\n\n    # We use [start, end) as a half-open interval below.\n    end += np.timedelta64(1, 'D')\n\n    # Get the previous/following Sunday to start/end.\n    # Pandas and numpy day-of-week conventions are Monday=0 and Sunday=6.\n    start_sun = start - np.timedelta64((start.dayofweek + 1) % 7, 'D')\n    end_sun = end + np.timedelta64(7 - end.dayofweek - 1, 'D')\n\n    # Create the heatmap and track ticks.\n    num_weeks = (end_sun - start_sun).days // 7\n    heatmap = np.zeros((7, num_weeks))\n    ticks = {}  # week number -> month name\n    for week in range(num_weeks):\n        for day in range(7):\n            date = start_sun + np.timedelta64(7 * week + day, 'D')\n            if date.day == 1:\n                ticks[week] = MONTHS[date.month - 1]\n            if date.dayofyear == 1:\n                ticks[week] += f'\\n{date.year}'\n            if start <= date < end:\n                heatmap[day, week] = series.get(date, 0)\n\n    # Get the coordinates, offset by 0.5 to align the ticks.\n    y = np.arange(8) - 0.5\n    x = np.arange(num_weeks + 1) - 0.5\n\n    # Plot the heatmap. Prefer pcolormesh over imshow so that the figure can be\n    # vectorized when saved to a compatible format. We must invert the axis for\n    # pcolormesh, but not for imshow, so that it reads top-bottom, left-right.\n    ax = ax or plt.gca()\n    mesh = ax.pcolormesh(x, y, heatmap, **kwargs)\n    ax.invert_yaxis()\n\n    # Set the ticks.\n    ax.set_xticks(list(ticks.keys()))\n    ax.set_xticklabels(list(ticks.values()))\n    ax.set_yticks(np.arange(7))\n    ax.set_yticklabels(DAYS)\n\n    # Set the current image and axes in the pyplot API.\n    plt.sca(ax)\n    plt.sci(mesh)\n\n    return ax\n\n\n# # Get some data, a series of values with datetime index.\n# data = np.random.randint(5, size=365)\n# data = pd.Series(data)\n# data.index = pd.date_range(start='2017-01-01', end='2017-12-31', freq='1D')\n\nrace_table[\"race_date\"] =  pd.to_datetime(race_table[\"race_date\"], format='%Y-%m-%d')\ndata = race_table[\"race_date\"].value_counts()\n\n# Create the figure. For the aspect ratio, one year is 7 days by 53 weeks.\n# We widen it further to account for the tick labels and color bar.\nfigsize = plt.figaspect(7 / 56)\nfig = plt.figure(figsize=(figsize))\n\n# Plot the heatmap with a color bar.\nax = date_heatmap(data, edgecolor='black')\nplt.colorbar(ticks=range(max(data.values)), pad=0.02)\ncmap = mpl.cm.get_cmap('Blues', 5)\nplt.set_cmap(cmap)\n# Force the cells to be square. If this is set, the size of the color bar\n# may look weird compared to the size of the heatmap. That can be corrected\n# by the aspect ratio of the figure or scale of the color bar.\nax.set_aspect('equal')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:54:51.875860Z","iopub.execute_input":"2022-08-13T11:54:51.876403Z","iopub.status.idle":"2022-08-13T11:54:52.216332Z","shell.execute_reply.started":"2022-08-13T11:54:51.876367Z","shell.execute_reply":"2022-08-13T11:54:52.215055Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Race number distribution</div>\n","metadata":{}},{"cell_type":"code","source":"values = race_table[\"race_number\"].value_counts().tolist()\nindex = tuple(race_table[\"race_number\"].value_counts().index.tolist())\nx = race_table[\"race_number\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(1, len(index)+1, 1)\n\nbars = plt.barh(x, width = values, align='center')\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Race number distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:04.107836Z","iopub.execute_input":"2022-08-13T11:36:04.108998Z","iopub.status.idle":"2022-08-13T11:36:04.368649Z","shell.execute_reply.started":"2022-08-13T11:36:04.108925Z","shell.execute_reply":"2022-08-13T11:36:04.367206Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Course Type distribution</div>\n","metadata":{"execution":{"iopub.status.busy":"2022-08-12T13:59:17.727333Z","iopub.execute_input":"2022-08-12T13:59:17.728494Z","iopub.status.idle":"2022-08-12T13:59:17.732396Z","shell.execute_reply.started":"2022-08-12T13:59:17.728448Z","shell.execute_reply":"2022-08-12T13:59:17.731608Z"}}},{"cell_type":"code","source":"values = race_table[\"course_type\"].value_counts().tolist()\nindex = tuple(race_table[\"course_type\"].value_counts().index.tolist())\nx = race_table[\"course_type\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center')\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Course Type distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:04.370217Z","iopub.execute_input":"2022-08-13T11:36:04.370583Z","iopub.status.idle":"2022-08-13T11:36:04.594655Z","shell.execute_reply.started":"2022-08-13T11:36:04.370550Z","shell.execute_reply":"2022-08-13T11:36:04.593239Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Track condition distribution</div>\n","metadata":{}},{"cell_type":"code","source":"values = race_table[\"track_condition\"].value_counts().tolist()\nindex = tuple(race_table[\"track_condition\"].value_counts().index.tolist())\nx = race_table[\"track_condition\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center')\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Track Condition distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:04.596110Z","iopub.execute_input":"2022-08-13T11:36:04.597456Z","iopub.status.idle":"2022-08-13T11:36:04.817014Z","shell.execute_reply.started":"2022-08-13T11:36:04.597409Z","shell.execute_reply":"2022-08-13T11:36:04.815458Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Race Type distribution</div>\n","metadata":{}},{"cell_type":"code","source":"values = race_table[\"race_type\"].value_counts().tolist()\nindex = tuple(race_table[\"race_type\"].value_counts().index.tolist())\nx = race_table[\"race_type\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center')\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Race Type distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:04.818429Z","iopub.execute_input":"2022-08-13T11:36:04.818758Z","iopub.status.idle":"2022-08-13T11:36:05.060363Z","shell.execute_reply.started":"2022-08-13T11:36:04.818729Z","shell.execute_reply":"2022-08-13T11:36:05.058951Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Purse distribution</div>","metadata":{"execution":{"iopub.status.busy":"2022-08-12T13:59:56.140909Z","iopub.execute_input":"2022-08-12T13:59:56.141336Z","iopub.status.idle":"2022-08-12T13:59:56.145814Z","shell.execute_reply.started":"2022-08-12T13:59:56.141298Z","shell.execute_reply":"2022-08-12T13:59:56.144756Z"}}},{"cell_type":"code","source":"import seaborn as sns\n\nax = sns.violinplot(x=race_table[\"purse\"])\nax.set(xlabel='Purse in US dollars', ylabel='Purse distribution')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:05.062448Z","iopub.execute_input":"2022-08-13T11:36:05.062854Z","iopub.status.idle":"2022-08-13T11:36:05.414579Z","shell.execute_reply.started":"2022-08-13T11:36:05.062821Z","shell.execute_reply":"2022-08-13T11:36:05.413167Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#1B4F72;\n            margin:0;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color: #1B4F72;\n            background-color:#AED6F1;\n            overflow:hidden;\n            font-weight:500\">Post time distribution</div>\n","metadata":{}},{"cell_type":"code","source":"plt.hist(race_table[\"post_time\"], bins=20)\nplt.xlabel(\"Time of day the race began\")\nplt.ylabel(\"Amount\")\nplt.title(\"Time of day the race began distribution\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:05.416445Z","iopub.execute_input":"2022-08-13T11:36:05.416795Z","iopub.status.idle":"2022-08-13T11:36:05.675385Z","shell.execute_reply.started":"2022-08-13T11:36:05.416766Z","shell.execute_reply":"2022-08-13T11:36:05.673830Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:220%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Start Table</div>\n\n<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:110%;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#D1F2EB;\n            overflow:hidden;\n            font-weight:500\">Fields:\n<li><code style=\"background: grey;\">track_id</code> - 3 character id for the track the race took place at. AQU -Aqueduct, BEL - Belmont, SAR - Saratoga.</li>\n<li><code style=\"background: grey;\">race_date</code> - date the race took place. YYYY-MM-DD.</li> \n<li><code style=\"background: grey;\">race_number</code> - Number of the race. Passed as 3 characters but can be cast or converted to int for this data set. </li>\n<li><code style=\"background: grey;\">program_number</code> - Program number of the horse in the race passed as 3 characters. Should remain 3 characters as it isn't limited to just numbers. Is essentially the unique identifier of the horse in the race.</li>\n<li><code style=\"background: grey;\">weight_carried</code> - Program number of the horse in the race passed as 3 characters. Should remain 3 characters as it isn't limited to just numbers. Is essentially the unique identifier of the horse in the race.</li>\n<li><code style=\"background: grey;\">jockey</code> - Name of the jockey on the horse in the race. 50 character max.</li> \n<li><code style=\"background: grey;\">odds</code> - Odds to win the race passed as an integer. Divide by 100 to derive the odds to 1. Example - 1280 would be 12.8-1.</li> \n</div> ","metadata":{}},{"cell_type":"code","source":"start_table = pd.read_csv(START_TABLE, sep = ',')\nprint(f\"Start table has {start_table.shape[0]} rows and {start_table.shape[1]} columns\")\nstart_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:05.677451Z","iopub.execute_input":"2022-08-13T11:36:05.677821Z","iopub.status.idle":"2022-08-13T11:36:05.718599Z","shell.execute_reply.started":"2022-08-13T11:36:05.677791Z","shell.execute_reply":"2022-08-13T11:36:05.717160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Basic macro statistics</div>","metadata":{}},{"cell_type":"code","source":"start_table.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:05.721231Z","iopub.execute_input":"2022-08-13T11:36:05.721832Z","iopub.status.idle":"2022-08-13T11:36:05.752780Z","shell.execute_reply.started":"2022-08-13T11:36:05.721781Z","shell.execute_reply":"2022-08-13T11:36:05.751420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Missing values</div>\n\n<p style=\"color:#117864;\">There are no missing values</p>","metadata":{}},{"cell_type":"code","source":"start_table.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:05.754835Z","iopub.execute_input":"2022-08-13T11:36:05.755352Z","iopub.status.idle":"2022-08-13T11:36:05.769478Z","shell.execute_reply.started":"2022-08-13T11:36:05.755307Z","shell.execute_reply":"2022-08-13T11:36:05.768188Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Unique values</div>","metadata":{}},{"cell_type":"code","source":"start_table.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:05.771573Z","iopub.execute_input":"2022-08-13T11:36:05.771934Z","iopub.status.idle":"2022-08-13T11:36:05.785949Z","shell.execute_reply.started":"2022-08-13T11:36:05.771903Z","shell.execute_reply":"2022-08-13T11:36:05.784984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Track ID distribution</div>","metadata":{}},{"cell_type":"code","source":"values = start_table[\"track_id\"].value_counts().tolist()\nindex = tuple(start_table[\"track_id\"].value_counts().index.tolist())\nx = start_table[\"track_id\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center', color=\"g\")\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Track id distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:05.787309Z","iopub.execute_input":"2022-08-13T11:36:05.787843Z","iopub.status.idle":"2022-08-13T11:36:05.988788Z","shell.execute_reply.started":"2022-08-13T11:36:05.787813Z","shell.execute_reply":"2022-08-13T11:36:05.987370Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Race date distribution</div>","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15,8))\nx = start_table[\"race_date\"].value_counts().index.tolist()\nx = np.asarray(x, dtype='datetime64[s]')\ny = start_table[\"race_date\"].value_counts().values.tolist()\nlabels = x\nplt.scatter(x = x, y = y, color=\"g\")\nplt.xlabel(\"Date the race took place\")\nplt.ylabel(\"Amount\")\nplt.title(\"Race date distribution\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:05.990154Z","iopub.execute_input":"2022-08-13T11:36:05.990526Z","iopub.status.idle":"2022-08-13T11:36:06.281226Z","shell.execute_reply.started":"2022-08-13T11:36:05.990492Z","shell.execute_reply":"2022-08-13T11:36:06.279844Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"start_table[\"race_date\"] =  pd.to_datetime(start_table[\"race_date\"], format='%Y-%m-%d')\ndata = start_table[\"race_date\"].value_counts()\n\n# Create the figure. For the aspect ratio, one year is 7 days by 53 weeks.\n# We widen it further to account for the tick labels and color bar.\nfigsize = plt.figaspect(7 / 56)\nfig = plt.figure(figsize=figsize)\n\n# Plot the heatmap with a color bar.\nax = date_heatmap(data, edgecolor='black')\nplt.colorbar(ticks=range(0, max(data.values), 20), pad=0.02)\ncmap = mpl.cm.get_cmap('Greens', 5)\nplt.set_cmap(cmap)\n\n# Force the cells to be square. If this is set, the size of the color bar\n# may look weird compared to the size of the heatmap. That can be corrected\n# by the aspect ratio of the figure or scale of the color bar.\nax.set_aspect('equal')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:06.282540Z","iopub.execute_input":"2022-08-13T11:36:06.283539Z","iopub.status.idle":"2022-08-13T11:36:06.576876Z","shell.execute_reply.started":"2022-08-13T11:36:06.283504Z","shell.execute_reply":"2022-08-13T11:36:06.575633Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Race number distribution</div>","metadata":{}},{"cell_type":"code","source":"values = start_table[\"race_number\"].value_counts().tolist()\nindex = tuple(start_table[\"race_number\"].value_counts().index.tolist())\nx = start_table[\"race_number\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(1, len(index)+1, 1)\n\nbars = plt.barh(x, width = values, align='center', color=\"g\")\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Race Number distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:06.578451Z","iopub.execute_input":"2022-08-13T11:36:06.578864Z","iopub.status.idle":"2022-08-13T11:36:06.841730Z","shell.execute_reply.started":"2022-08-13T11:36:06.578834Z","shell.execute_reply":"2022-08-13T11:36:06.840398Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Program number distribution</div>","metadata":{}},{"cell_type":"code","source":"values = start_table[\"program_number\"].value_counts().tolist()\nindex = tuple(start_table[\"program_number\"].value_counts().index.tolist())\nx = start_table[\"program_number\"].value_counts().index.tolist()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center', color=\"g\")\n\nax.set_yticks(y_pos)\n\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Program number distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:06.843382Z","iopub.execute_input":"2022-08-13T11:36:06.843867Z","iopub.status.idle":"2022-08-13T11:36:07.146967Z","shell.execute_reply.started":"2022-08-13T11:36:06.843819Z","shell.execute_reply":"2022-08-13T11:36:07.145810Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Weight carried distribution</div>","metadata":{}},{"cell_type":"code","source":"ax = sns.violinplot(x=start_table[\"weight_carried\"], color = \"g\")\nax.set(xlabel=' Weight carried', ylabel='Weight distribution')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:07.148580Z","iopub.execute_input":"2022-08-13T11:36:07.149066Z","iopub.status.idle":"2022-08-13T11:36:07.442288Z","shell.execute_reply.started":"2022-08-13T11:36:07.149022Z","shell.execute_reply":"2022-08-13T11:36:07.440913Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#117864;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#117864;\n            background-color:#A3E4D7;\n            overflow:hidden;\n            font-weight:500\">Odds distribution</div>","metadata":{"execution":{"iopub.status.busy":"2022-08-12T14:12:54.890614Z","iopub.execute_input":"2022-08-12T14:12:54.891770Z","iopub.status.idle":"2022-08-12T14:12:54.896122Z","shell.execute_reply.started":"2022-08-12T14:12:54.891725Z","shell.execute_reply":"2022-08-12T14:12:54.895157Z"}}},{"cell_type":"code","source":"ax = sns.violinplot(x=start_table[\"odds\"], color = \"g\")\nax.set(xlabel=' Odds to win the race', ylabel='Odds distribution')","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:07.447723Z","iopub.execute_input":"2022-08-13T11:36:07.448126Z","iopub.status.idle":"2022-08-13T11:36:07.755229Z","shell.execute_reply.started":"2022-08-13T11:36:07.448080Z","shell.execute_reply":"2022-08-13T11:36:07.753778Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:220%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Tracking Table</div>\n\n<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:110%;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#FADBD8;\n            overflow:hidden;\n            font-weight:500\">Fields:\n<li><code style=\"background: grey;\">track_id</code> - 3 character id for the track the race took place at. AQU -Aqueduct, BEL - Belmont, SAR - Saratoga.</li>\n<li><code style=\"background: grey;\">race_date</code> - date the race took place. YYYY-MM-DD.</li> \n<li><code style=\"background: grey;\">race_number</code> - Number of the race. Passed as 3 characters but can be cast or converted to int for this data set. </li>\n<li><code style=\"background: grey;\">program_number</code> - Program number of the horse in the race passed as 3 characters. Should remain 3 characters as it isn't limited to just numbers. Is essentially the unique identifier of the horse in the race.</li>\n<li><code style=\"background: grey;\">latitude</code> - The latitude of the horse in the race passed as a float. </li>\n<li><code style=\"background: grey;\">longitude</code> - The longitude of the horse in the race passed as a float.</li> \n</div>","metadata":{}},{"cell_type":"code","source":"tracking_table = pd.read_csv(TRACKING_TABLE, sep = ',')\nprint(f\"Tracking table has {tracking_table.shape[0]} rows and {tracking_table.shape[1]} columns\")\ntracking_table.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:07.757258Z","iopub.execute_input":"2022-08-13T11:36:07.757752Z","iopub.status.idle":"2022-08-13T11:36:14.366571Z","shell.execute_reply.started":"2022-08-13T11:36:07.757707Z","shell.execute_reply":"2022-08-13T11:36:14.365297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Basic macro statistics</div>","metadata":{}},{"cell_type":"code","source":"tracking_table.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:14.367963Z","iopub.execute_input":"2022-08-13T11:36:14.368319Z","iopub.status.idle":"2022-08-13T11:36:15.137898Z","shell.execute_reply.started":"2022-08-13T11:36:14.368287Z","shell.execute_reply":"2022-08-13T11:36:15.136530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Missing values</div>\n\n<p style=\"color:#B03A2E;\">There are no missing values</p>","metadata":{}},{"cell_type":"code","source":"tracking_table.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:15.139466Z","iopub.execute_input":"2022-08-13T11:36:15.139990Z","iopub.status.idle":"2022-08-13T11:36:15.838428Z","shell.execute_reply.started":"2022-08-13T11:36:15.139900Z","shell.execute_reply":"2022-08-13T11:36:15.837014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Unique values</div>","metadata":{}},{"cell_type":"code","source":"tracking_table.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:15.839747Z","iopub.execute_input":"2022-08-13T11:36:15.840259Z","iopub.status.idle":"2022-08-13T11:36:19.129935Z","shell.execute_reply.started":"2022-08-13T11:36:15.840172Z","shell.execute_reply":"2022-08-13T11:36:19.128603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Track ID distribution</div>","metadata":{}},{"cell_type":"code","source":"values = tracking_table[\"track_id\"].value_counts().tolist()\nindex = tuple(tracking_table[\"track_id\"].value_counts().index.tolist())\nx = tracking_table[\"track_id\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center', color=\"r\")\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Track id distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:19.131211Z","iopub.execute_input":"2022-08-13T11:36:19.131532Z","iopub.status.idle":"2022-08-13T11:36:20.309811Z","shell.execute_reply.started":"2022-08-13T11:36:19.131504Z","shell.execute_reply":"2022-08-13T11:36:20.308491Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Race date distribution</div>","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(15,8))\nx = tracking_table[\"race_date\"].value_counts().index.tolist()\nx = np.asarray(x, dtype='datetime64[s]')\ny = tracking_table[\"race_date\"].value_counts().values.tolist()\nlabels = x\nplt.scatter(x = x, y = y, color=\"r\")\nplt.xlabel(\"Date the race took place\")\nplt.ylabel(\"Amount\")\nplt.title(\"Race date distribution\")","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:20.311514Z","iopub.execute_input":"2022-08-13T11:36:20.311847Z","iopub.status.idle":"2022-08-13T11:36:21.256288Z","shell.execute_reply.started":"2022-08-13T11:36:20.311819Z","shell.execute_reply":"2022-08-13T11:36:21.254726Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tracking_table[\"race_date\"] =  pd.to_datetime(tracking_table[\"race_date\"], format='%Y-%m-%d')\ndata = tracking_table[\"race_date\"].value_counts()\n\n# Create the figure. For the aspect ratio, one year is 7 days by 53 weeks.\n# We widen it further to account for the tick labels and color bar.\nfigsize = plt.figaspect(7 / 56)\nfig = plt.figure(figsize=figsize)\n\n# Plot the heatmap with a color bar.\nax = date_heatmap(data, edgecolor='black')\nplt.colorbar(ticks=range(0,max(data.values),10000), pad=0.02)\ncmap = mpl.cm.get_cmap('Reds', 5)\nplt.set_cmap(cmap)\n\n# Force the cells to be square. If this is set, the size of the color bar\n# may look weird compared to the size of the heatmap. That can be corrected\n# by the aspect ratio of the figure or scale of the color bar.\nax.set_aspect('equal')","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:21.257607Z","iopub.execute_input":"2022-08-13T11:36:21.259484Z","iopub.status.idle":"2022-08-13T11:36:22.508905Z","shell.execute_reply.started":"2022-08-13T11:36:21.259445Z","shell.execute_reply":"2022-08-13T11:36:22.507657Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Race number distribution</div>","metadata":{}},{"cell_type":"code","source":"values = tracking_table[\"race_number\"].value_counts().tolist()\nindex = tuple(tracking_table[\"race_number\"].value_counts().index.tolist())\nx = tracking_table[\"race_number\"].value_counts().index.tolist()\n# plt.rcdefaults()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(1, len(index)+1, 1)\n\nbars = plt.barh(x, width = values, align='center', color=\"r\")\n\nax.set_yticks(y_pos)\n\n# ax.set_xticklabels(x_ticks)\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Race Number distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:22.510340Z","iopub.execute_input":"2022-08-13T11:36:22.510841Z","iopub.status.idle":"2022-08-13T11:36:22.887380Z","shell.execute_reply.started":"2022-08-13T11:36:22.510800Z","shell.execute_reply":"2022-08-13T11:36:22.885897Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div style=\"padding:20px; \n            color:#B03A2E;\n            margin:10px;\n            font-size:150%;\n            text-align:center;\n            display:fill;\n            border-radius:10px;\n            border-style: solid;\n            border-color:#B03A2E;\n            background-color:#F5B7B1;\n            overflow:hidden;\n            font-weight:500\">Program number distribution</div>","metadata":{}},{"cell_type":"code","source":"values = tracking_table[\"program_number\"].value_counts().tolist()\nindex = tuple(tracking_table[\"program_number\"].value_counts().index.tolist())\nx = tracking_table[\"program_number\"].value_counts().index.tolist()\nfig, ax = plt.subplots()\n\ny_pos = np.arange(len(index))\n\nbars = plt.barh(x, width = values, align='center', color=\"r\")\n\nax.set_yticks(y_pos)\n\nax.set_yticklabels(index)\n\n# plt.xlim(0,1)\nax.invert_yaxis()  # labels read top-to-bottom\nax.set_xlabel('Number')\nax.set_title('''Program number distribution''', loc = 'center')\nax.xaxis.grid(color='gray', linestyle='dashed')\n\nplt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-08-13T11:36:22.888737Z","iopub.execute_input":"2022-08-13T11:36:22.889240Z","iopub.status.idle":"2022-08-13T11:36:24.126004Z","shell.execute_reply.started":"2022-08-13T11:36:22.889192Z","shell.execute_reply":"2022-08-13T11:36:24.124635Z"},"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_number = 1\ntrack_id = \"SAR\"\nday = 22\nmonth = 8\nyear = 2019\n\nsubset = tracking_table[(tracking_table[\"race_number\"]==race_number) &\n                        (tracking_table[\"track_id\"]==track_id) &\n                        (tracking_table[\"race_date\"].dt.month==month) &\n                        (tracking_table[\"race_date\"].dt.day==day)]\nif len(subset)>5000:\n    subset = subset.sample(5000)\n    \nx = subset[\"longitude\"]\ny = subset[\"latitude\"]\n\n# Layout\nlayout = go.Layout(\n    title = f\"Longitude and Latitude for track id {track_id} race {7} on date {day}/{month}/{year}\",\n    xaxis = dict(\n        title = \"Longitude\"\n    ),\n    yaxis = dict(\n        title = \"Latitude\"\n    )\n\n)\n\nfig = go.Figure(layout=layout)\n\n# Add scatter trace\nfig.add_trace(\n    go.Scatter(\n        mode = \"markers\",\n        x = x,\n        y = y,\n        marker = dict(\n            color = \"darkturquoise\",\n            size = 6,\n            opacity = 0.4,\n            line = dict(color=\"burlywood\", width=1)\n        ),\n        showlegend = False\n    )\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T11:36:24.127730Z","iopub.execute_input":"2022-08-13T11:36:24.128171Z","iopub.status.idle":"2022-08-13T11:36:25.484796Z","shell.execute_reply.started":"2022-08-13T11:36:24.128076Z","shell.execute_reply":"2022-08-13T11:36:25.482907Z"},"trusted":true},"execution_count":null,"outputs":[]}]}