{"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":"<img src=\"https://storage.googleapis.com/kaggle-competitions/kaggle/37644/logos/header.png?t=2022-08-05-15-26-16\" width=1500 class=\"center\">","metadata":{}},{"cell_type":"markdown","source":"<h1 style=\"font-size:60px;\" align=\"center\">🐎 Big Data Derby 2022 Analysis 🐎</h1>","metadata":{}},{"cell_type":"markdown","source":"## **Goal of the Competition** \n\nThe 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\nYour 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.\n\n## **Context** \n\nInjury 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.\n\nA 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.\n\nIn 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.\n\nThe 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.\n\nWith 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.\n\n## Columns in Dataset\n***\n\n- `track_id`: 3 character id for the track the race took place at. AQU -Aqueduct, BEL - Belmont, SAR - Saratoga. \n- `race_date`: date the race took place. YYYY-MM-DD.\n- `race_number`: Number of the race. Passed as 3 characters but can be cast or converted to int for this data set.\n- `program_number`: 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.\n- `trakus_index`:  Trakus is a speed-distance curve measurement system for thoroughbred horseracing that measures the speed of each horse in the race with respect to its distance travelled in the race and from that measurement, the distance between horses at the time of POC (point of call) can be measured.\n- `latitude`: The latitude of the horse in the race passed as a float. \n- `longitude`: The longitude of the horse in the race passed as a float. \n- `distance_id`: Distance of the race in furlongs passed as an integer. Example - 600 would be 6 furlongs. \n- `course_type`: The course the race was run over passed as one character. M - Hurdle, D - Dirt, O - Outer turf, I - Inner turf, T - turf.\n- `track_condition`: 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.\n- `run_up_distance`: “Run-up” is the distance from where the gate is placed and the timing of the race begins – that is, the point at which the horses reach the published distance of the race.\n- `race_type`: 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.\n- `purse`: In horse racing, the term purse refers to the total amount of money paid out to the owners of horses racing at a particular track over a given period of time, or to the percentages of a race's total purse that are awarded to each of the highest finishers. \n- `post_time`: Post time is the designated starting time of a horse race.\n- `weight_carried`:  horse can carry a weight during a race which includes the weight of the saddle and the person riding it.\n- `jockey`: Name of jockey (the guys that actually rise the horse in the race)\n- `odds`: the return you can expect to get if the horse you bet on is successful","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom pandas_profiling import ProfileReport\n\nimport plotly.express as px #graphing\nimport plotly.graph_objects as go #graphing\nfrom plotly.subplots import make_subplots #graphing\nimport plotly.figure_factory as ff #graphing\nimport matplotlib.pyplot as plt #graphing\nimport seaborn as sns #graphing\nimport missingno as msno #describe data\nimport os\n\ncolors = [\"#FFFFFF\", \"#6CD4FF\", \"#F7DF00\", \"#E60000\"]\n\nfrom plotly.offline import plot, iplot, init_notebook_mode\nimport plotly.graph_objs as go\ninit_notebook_mode(connected=True)\n%matplotlib inline\n\nplt.rcParams[\"figure.figsize\"] = (12, 8)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:28:15.875358Z","iopub.execute_input":"2022-08-18T14:28:15.875731Z","iopub.status.idle":"2022-08-18T14:28:20.965157Z","shell.execute_reply.started":"2022-08-18T14:28:15.875699Z","shell.execute_reply":"2022-08-18T14:28:20.964056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Dataset Overview","metadata":{}},{"cell_type":"code","source":"for dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:36:04.612672Z","iopub.execute_input":"2022-08-18T13:36:04.613455Z","iopub.status.idle":"2022-08-18T13:36:04.621352Z","shell.execute_reply.started":"2022-08-18T13:36:04.613413Z","shell.execute_reply":"2022-08-18T13:36:04.619970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# horse/jockey race data\nnyra_start_table = pd.read_csv(\"../input/big-data-derby-2022/nyra_start_table.csv\", low_memory = False)\ndisplay(nyra_start_table.info())","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:31:00.088716Z","iopub.execute_input":"2022-08-18T14:31:00.089489Z","iopub.status.idle":"2022-08-18T14:31:00.136331Z","shell.execute_reply.started":"2022-08-18T14:31:00.089455Z","shell.execute_reply":"2022-08-18T14:31:00.135372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# racetrack race data \nnyra_race_table = pd.read_csv(\"../input/big-data-derby-2022/nyra_race_table.csv\", low_memory = False)\ndisplay(nyra_race_table.info())","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:31:06.133667Z","iopub.execute_input":"2022-08-18T14:31:06.134284Z","iopub.status.idle":"2022-08-18T14:31:06.158386Z","shell.execute_reply.started":"2022-08-18T14:31:06.134248Z","shell.execute_reply":"2022-08-18T14:31:06.157220Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# tracking data \nnyra_tracking_table = pd.read_csv(\"../input/big-data-derby-2022/nyra_tracking_table.csv\", low_memory = False)\ndisplay(nyra_tracking_table.info())","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:31:44.813113Z","iopub.execute_input":"2022-08-18T14:31:44.813480Z","iopub.status.idle":"2022-08-18T14:31:51.005730Z","shell.execute_reply.started":"2022-08-18T14:31:44.813448Z","shell.execute_reply":"2022-08-18T14:31:51.004393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtype_dict = {\"track_id\": object ,\n              #\"race_date\" : will be read with \"parse_dates\" parameter\n              \"race_number\" : np.int8, \n              \"program_number\" : object,\n              \"trakus_index\" : np.int16,  \n              \"latitude\" : np.float64,\n              \"longitude\" : np.float64,\n              \"distance_id\" : np.int16,  \n              \"course_type\" : object, \n              \"track_condition\" : object,\n              \"run_up_distance\" : np.int8,  \n              \"race_type\" : object, \n              \"purse\" : np.int32,  \n              \"post_time\" : np.int16,  \n              \"weight_carried\" : np.int16,  \n              \"jockey\" : object, \n              \"odds\" : np.int16,\n             }\n\ndf = pd.read_csv(\"../input/big-data-derby-2022/nyra_2019_complete.csv\", \n                 dtype = dtype_dict, parse_dates=[\"race_date\"])","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:33:05.598952Z","iopub.execute_input":"2022-08-18T14:33:05.599957Z","iopub.status.idle":"2022-08-18T14:33:13.609922Z","shell.execute_reply.started":"2022-08-18T14:33:05.599919Z","shell.execute_reply":"2022-08-18T14:33:13.608876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"By passing the data types directly to the `read_csv()` function, we were able to **reduce the required memory for storage from 678 MB to 438 MB!**","metadata":{}},{"cell_type":"code","source":"data = ProfileReport(df, minimal=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:14:05.667371Z","iopub.execute_input":"2022-08-18T13:14:05.667791Z","iopub.status.idle":"2022-08-18T13:14:05.696471Z","shell.execute_reply.started":"2022-08-18T13:14:05.667755Z","shell.execute_reply":"2022-08-18T13:14:05.695512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.to_widgets()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:14:09.317639Z","iopub.execute_input":"2022-08-18T13:14:09.318465Z","iopub.status.idle":"2022-08-18T13:15:06.049786Z","shell.execute_reply.started":"2022-08-18T13:14:09.318414Z","shell.execute_reply":"2022-08-18T13:15:06.048470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Analysis from above Report\n1. The four csv files have three common key columns: `track_id`, `race_data`, `race_number`\n2. *We don't have any missing values*.\n3. We have 6 categorical variables, 10 numeric variables and 1 DateTime variable.\n\n","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize = (18,20))\nax1 = fig.add_subplot(211)\n\nsns.heatmap(df.corr(),cmap = \"coolwarm\",vmin = -1, vmax = 1,annot=True)\nax1.set_title(\"Correlation of features to winnning odds\")\n\nplt.tight_layout\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:15:13.765337Z","iopub.execute_input":"2022-08-18T13:15:13.765834Z","iopub.status.idle":"2022-08-18T13:15:16.341418Z","shell.execute_reply.started":"2022-08-18T13:15:13.765778Z","shell.execute_reply":"2022-08-18T13:15:16.340453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Tracking","metadata":{}},{"cell_type":"code","source":"nyra_tracking_table['race_date'] = pd.to_datetime(nyra_tracking_table['race_date'])\nnyra_tracking_table['day'], nyra_tracking_table['month'] = nyra_tracking_table['race_date'].dt.day, nyra_tracking_table['race_date'].dt.month","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:15:20.742958Z","iopub.execute_input":"2022-08-18T13:15:20.743522Z","iopub.status.idle":"2022-08-18T13:15:22.316234Z","shell.execute_reply.started":"2022-08-18T13:15:20.743484Z","shell.execute_reply":"2022-08-18T13:15:22.315181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_tracking_table['track_id'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:15:25.502642Z","iopub.execute_input":"2022-08-18T13:15:25.503625Z","iopub.status.idle":"2022-08-18T13:15:25.817615Z","shell.execute_reply.started":"2022-08-18T13:15:25.503585Z","shell.execute_reply":"2022-08-18T13:15:25.816654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Tracking Ids:\n'AQU': AQUEDUCT, \n'BEL': BELMONT PARK, \n'SAR': SARATOGA","metadata":{}},{"cell_type":"markdown","source":"## Aqueduct track","metadata":{}},{"cell_type":"code","source":"nyra_tracking_0 = nyra_tracking_table[nyra_tracking_table[\"track_id\"] == \"AQU\"]\nnyra_tracking_1 = nyra_tracking_0[nyra_tracking_0[\"month\"] == 11]\n\nplt.style.use(\"dark_background\")\nplt.figure(figsize = (16, 8))\nsns.scatterplot(data = nyra_tracking_1, x = \"longitude\", y = \"latitude\", hue = \"race_number\", palette = \"Paired\")\n\nplt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\nplt.legend()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:15:29.027802Z","iopub.execute_input":"2022-08-18T13:15:29.028543Z","iopub.status.idle":"2022-08-18T13:15:43.484806Z","shell.execute_reply.started":"2022-08-18T13:15:29.028497Z","shell.execute_reply":"2022-08-18T13:15:43.483932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Belmont Park track","metadata":{}},{"cell_type":"code","source":"nyra_tracking_0 = nyra_tracking_table[nyra_tracking_table[\"track_id\"] == \"BEL\"]\nnyra_tracking_1 = nyra_tracking_0[nyra_tracking_0[\"month\"] == 5]\n\nplt.style.use(\"dark_background\")\nplt.figure(figsize = (16, 8))\nsns.scatterplot(data = nyra_tracking_1, x = \"longitude\", y = \"latitude\", hue = \"race_number\", palette = \"Paired\")\n\nplt.title(\"track_id = BEL, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:15:52.523379Z","iopub.execute_input":"2022-08-18T13:15:52.523867Z","iopub.status.idle":"2022-08-18T13:16:02.716268Z","shell.execute_reply.started":"2022-08-18T13:15:52.523828Z","shell.execute_reply":"2022-08-18T13:16:02.715376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Saratoga track","metadata":{}},{"cell_type":"code","source":"nyra_tracking_0 = nyra_tracking_table[nyra_tracking_table[\"track_id\"] == \"SAR\"]\nnyra_tracking_1 = nyra_tracking_0[nyra_tracking_0[\"month\"] == 9]\n\nplt.style.use(\"dark_background\")\nplt.figure(figsize = (16, 8))\nsns.scatterplot(data = nyra_tracking_1, x = \"longitude\", y = \"latitude\", hue = \"race_number\", palette = \"Paired\")\n\nplt.title(\"track_id = SAR, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:18:26.190567Z","iopub.execute_input":"2022-08-18T13:18:26.191516Z","iopub.status.idle":"2022-08-18T13:18:29.207580Z","shell.execute_reply.started":"2022-08-18T13:18:26.191465Z","shell.execute_reply":"2022-08-18T13:18:29.206594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Carried Weight & Steeplechase Races\n\n> The Kentucky Derby, for example, has a weight limit of 126 lb (57 kg) including the jockey's equipment. The weight of a jockey usually ranges from 108 to 118 lb (49 to 54 kg).\n\nThe average weight of each jockey is plotted in the below boxplot.","metadata":{}},{"cell_type":"code","source":"sns.boxplot(nyra_start_table.groupby(\"jockey\").weight_carried.mean())","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:18:42.390037Z","iopub.execute_input":"2022-08-18T13:18:42.390834Z","iopub.status.idle":"2022-08-18T13:18:42.578796Z","shell.execute_reply.started":"2022-08-18T13:18:42.390794Z","shell.execute_reply":"2022-08-18T13:18:42.577651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"What's strange is that there are some average `weight_carried` above 140 lbs. \nLet's have a look at the top 5 heaviest jockeys.","metadata":{}},{"cell_type":"code","source":"for jockey in (nyra_start_table.groupby(\"jockey\").weight_carried.mean().sort_values(ascending=False).head(5).index):\n    display(nyra_start_table[nyra_start_table.jockey == jockey])","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:18:47.629219Z","iopub.execute_input":"2022-08-18T13:18:47.630440Z","iopub.status.idle":"2022-08-18T13:18:47.689042Z","shell.execute_reply.started":"2022-08-18T13:18:47.630390Z","shell.execute_reply":"2022-08-18T13:18:47.687959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":">  Those high weights are in what are called steeplechase races, where horse and jockey jump over fences throughout the race. \n\n\nAccording to the competition host's answer in this [this discussion](https://www.kaggle.com/competitions/big-data-derby-2022/discussion/344315)","metadata":{}},{"cell_type":"markdown","source":"We have `track_id`, `race_date`, `race_number` common in all four csv files. So, we will combine them in `race_id`.","metadata":{}},{"cell_type":"code","source":"key_columns = [\"track_id\", \"race_date\", \"race_number\"]\n\nfor nyra_df in [nyra_start_table, nyra_race_table, nyra_tracking_table, df]:\n    nyra_df[\"race_id\"] = nyra_df[key_columns].astype(str).agg('_'.join, axis=1)\n    \ndisplay(nyra_start_table[key_columns].astype(str).agg('_'.join, axis=1))","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:52:15.561929Z","iopub.execute_input":"2022-08-18T14:52:15.562304Z","iopub.status.idle":"2022-08-18T14:58:05.303532Z","shell.execute_reply.started":"2022-08-18T14:52:15.562274Z","shell.execute_reply":"2022-08-18T14:58:05.302625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = pd.merge(nyra_race_table, nyra_start_table.groupby('race_id').weight_carried.mean().to_frame(), on='race_id')\ndisplay(temp[temp.weight_carried >= 127])\n\nsteeplechase_races = temp[temp.weight_carried >= 127].race_id.values\nprint(\"Steeplechase Races\", steeplechase_races)","metadata":{"execution":{"iopub.status.busy":"2022-08-18T15:03:08.736658Z","iopub.execute_input":"2022-08-18T15:03:08.737771Z","iopub.status.idle":"2022-08-18T15:03:08.778801Z","shell.execute_reply.started":"2022-08-18T15:03:08.737734Z","shell.execute_reply":"2022-08-18T15:03:08.777636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Trakus Index Race Animation","metadata":{}},{"cell_type":"code","source":"df1 = pd.read_csv(\"../input/big-data-derby-2022/nyra_2019_complete.csv\", parse_dates=[\"race_date\"], low_memory=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:28:37.113263Z","iopub.execute_input":"2022-08-18T14:28:37.113645Z","iopub.status.idle":"2022-08-18T14:28:52.362237Z","shell.execute_reply.started":"2022-08-18T14:28:37.113608Z","shell.execute_reply":"2022-08-18T14:28:52.361172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Jockey: **Samuel Camacho Jr**.","metadata":{}},{"cell_type":"code","source":"jockey = df1[df1[\"jockey\"] == \"Samuel Camacho Jr.\"]\njockey6 = jockey[jockey[\"race_number\"] == 6]\njockeyBEL = jockey6[jockey6[\"track_id\"] == \"BEL\"]\njockeyALW = jockeyBEL[jockeyBEL[\"race_type\"] == \"ALW\"]\njockeyCLM = jockeyBEL[jockeyBEL[\"race_type\"] == \"CLM\"]\njockeyALW = jockeyALW.sort_values(by = \"trakus_index\", ascending = True)\n\nfig = px.scatter(jockeyALW, x = \"longitude\", y = \"latitude\", hover_data = [\"race_type\", \"track_id\"],\n                 animation_frame = \"longitude\",\n                 range_y = (40.7122, 40.718),\n                 range_x = (-73.719, -73.73),\n                 #size = \"trakus_index\",\n                 color = \"trakus_index\", color_continuous_scale = \"Turbo\", range_color = (0, 299),\n                 title = \"Samuel Camacho Jr. - Trakus Index,  Race Number = 6,  track_id = BEL\")\n\nfig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30\nfig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5\nfig.update_traces(marker = dict(symbol = \"circle-open\", size = 20)) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:29:04.376917Z","iopub.execute_input":"2022-08-18T14:29:04.378006Z","iopub.status.idle":"2022-08-18T14:29:07.879594Z","shell.execute_reply.started":"2022-08-18T14:29:04.377960Z","shell.execute_reply":"2022-08-18T14:29:07.878647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Jockey: **Thomas Garner**","metadata":{}},{"cell_type":"code","source":"jockey = df1[df1[\"jockey\"] == \"Thomas Garner\"]\njockey6 = jockey[jockey[\"race_number\"] == 1]\njockeyBEL = jockey6[jockey6[\"track_id\"] == \"BEL\"]\njockeyALW = jockeyBEL[jockeyBEL[\"race_type\"] == \"STK\"]\njockeyCLM = jockeyBEL[jockeyBEL[\"race_type\"] == \"STK\"]\njockeyALW = jockeyALW.sort_values(by = \"trakus_index\", ascending = True)\n\nfig = px.scatter(jockeyALW, x = \"longitude\", y = \"latitude\", hover_data = [\"race_type\", \"track_id\"],\n                 animation_frame = \"longitude\",\n                 range_y = (40.7161, 43.0707),\n                 range_x = (-73.7205, -73.7680),\n                # size = \"trakus_index\",\n                 color = \"trakus_index\", color_continuous_scale = \"Turbo\", range_color = (0, 299),\n                 title = \"Thomas Garner - Trakus Index,  Race Number = 1,  track_id = BEL\")\n\nfig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30\nfig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5\nfig.update_traces(marker = dict(symbol = \"circle-open\", size = 20)) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:29:17.789275Z","iopub.execute_input":"2022-08-18T14:29:17.789898Z","iopub.status.idle":"2022-08-18T14:29:23.304883Z","shell.execute_reply.started":"2022-08-18T14:29:17.789863Z","shell.execute_reply":"2022-08-18T14:29:23.300846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Jockey: **Flavien Prat**","metadata":{}},{"cell_type":"code","source":"jockey = df1[df1[\"jockey\"] == \"Flavien Prat\"]\njockey6 = jockey[jockey[\"race_number\"] == 6]\njockeyBEL = jockey6[jockey6[\"track_id\"] == \"BEL\"]\njockeyALW = jockeyBEL[jockeyBEL[\"race_type\"] == \"ALW\"]\njockeyCLM = jockeyBEL[jockeyBEL[\"race_type\"] == \"CLM\"]\njockeyALW = jockeyALW.sort_values(by = \"trakus_index\", ascending = True)\n\nfig = px.scatter(jockeyALW, x = \"longitude\", y = \"latitude\", hover_data = [\"race_type\", \"track_id\"],\n                 animation_frame = \"longitude\",\n                 range_y = (40.7122, 40.718),\n                 range_x = (-73.719, -73.73),\n                # size = \"trakus_index\",\n                 color = \"trakus_index\", color_continuous_scale = \"Turbo\", range_color = (0, 299),\n                 title = \"Flavien Prat - Trakus Index,  Race Number = 6,  track_id = BEL\")\n\nfig.layout.updatemenus[0].buttons[0].args[1]['frame']['duration'] = 30\nfig.layout.updatemenus[0].buttons[0].args[1]['transition']['duration'] = 5\nfig.update_traces(marker = dict(symbol = \"circle-open\", size = 20)) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:29:37.633638Z","iopub.execute_input":"2022-08-18T14:29:37.634032Z","iopub.status.idle":"2022-08-18T14:29:39.497615Z","shell.execute_reply.started":"2022-08-18T14:29:37.634000Z","shell.execute_reply":"2022-08-18T14:29:39.496750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Jockey Flavien Prat - Trakus Index Race Pathing by Odds of Winning","metadata":{}},{"cell_type":"code","source":"jockey = df1[df1[\"jockey\"] == \"Flavien Prat\"]\nraces_bel = jockey[jockey[\"track_id\"] == 'BEL']\n\nfor odds in sorted([690, 650, 1840, 70, 520, 2140, 400, 2775, 700, 160, 1910, 1030, 660]):\n    \n    df0 = races_bel[races_bel[\"odds\"] == odds]\n    \n    fig = px.scatter(df0, x = \"longitude\", y = \"latitude\", opacity = 0.8,\n                     hover_data = [\"race_date\", \"distance_id\", \"purse\"],\n                     color = \"trakus_index\", color_continuous_scale = \"Turbo\", #range_color = (0, 399),\n                     title = f\"Flavien Prat Trakus Index Race Pathing,  Odds: {odds}  track_id = BEL\")\n\n    fig.update_traces(marker = dict(symbol = \"square-open\", size = 20)) # scaling the markers\n    fig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 12))\n    fig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T14:30:13.075506Z","iopub.execute_input":"2022-08-18T14:30:13.076236Z","iopub.status.idle":"2022-08-18T14:30:14.887111Z","shell.execute_reply.started":"2022-08-18T14:30:13.076200Z","shell.execute_reply":"2022-08-18T14:30:14.886068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Odds of Winning Race","metadata":{}},{"cell_type":"code","source":"fig = px.scatter(nyra_start_table, x = \"weight_carried\", y = \"odds\", hover_data = [\"race_number\", \"jockey\"],\n                 color = \"odds\", color_continuous_scale = colors, range_color = (0, 9999),\n                 title = \"Odds by Weight Carried\")\n\nfig.update_traces(marker = dict(size = 8, symbol = \"circle\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 18))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:40:26.279344Z","iopub.execute_input":"2022-08-18T13:40:26.282540Z","iopub.status.idle":"2022-08-18T13:40:26.650432Z","shell.execute_reply.started":"2022-08-18T13:40:26.282490Z","shell.execute_reply":"2022-08-18T13:40:26.649593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_start_table['race_date'] = pd.to_datetime(nyra_start_table['race_date'])\nnyra_start_table['day'], nyra_start_table['month'] = nyra_start_table['race_date'].dt.day, nyra_start_table['race_date'].dt.month","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:40:37.597007Z","iopub.execute_input":"2022-08-18T13:40:37.597612Z","iopub.status.idle":"2022-08-18T13:40:37.617268Z","shell.execute_reply.started":"2022-08-18T13:40:37.597572Z","shell.execute_reply":"2022-08-18T13:40:37.616370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_start_table, x = \"weight_carried\", y = \"day\", hover_data = [\"race_number\", \"jockey\"],\n                 color = \"odds\", color_continuous_scale = colors, range_color = (0, 9999),\n                 title = \"Odds by Day of Event and Weight Carried\")\n\nfig.update_traces(marker = dict(size = 9, symbol = \"square\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 18))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:40:40.656916Z","iopub.execute_input":"2022-08-18T13:40:40.658897Z","iopub.status.idle":"2022-08-18T13:40:40.915602Z","shell.execute_reply.started":"2022-08-18T13:40:40.658844Z","shell.execute_reply":"2022-08-18T13:40:40.914746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_start_table, x = \"weight_carried\", y = \"month\", hover_data = [\"race_number\", \"jockey\"],\n                 color = \"odds\", color_continuous_scale = colors, range_color = (0, 9999),\n                 title = \"Odds by Month of Event and Weight Carried\")\n\nfig.update_traces(marker = dict(size = 11, symbol = \"circle\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 18))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:40:46.687594Z","iopub.execute_input":"2022-08-18T13:40:46.688404Z","iopub.status.idle":"2022-08-18T13:40:46.945157Z","shell.execute_reply.started":"2022-08-18T13:40:46.688338Z","shell.execute_reply":"2022-08-18T13:40:46.943484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter(nyra_race_table, x = \"post_time\", y = \"run_up_distance\", hover_data = [\"race_number\", \"course_type\"],\n                 color = \"race_number\", color_discrete_sequence = colors, #range_color = (0, 9999),\n                 title = \"Post Time by Run Up Distance\")\n\nfig.update_traces(marker = dict(size = 4, symbol = \"circle\")) # scaling the markers\nfig.update_layout(template = \"plotly_dark\", font = dict(family = \"PT Sans\", size = 20))\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-18T13:40:53.327909Z","iopub.execute_input":"2022-08-18T13:40:53.328295Z","iopub.status.idle":"2022-08-18T13:40:53.427252Z","shell.execute_reply.started":"2022-08-18T13:40:53.328263Z","shell.execute_reply":"2022-08-18T13:40:53.426155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**A special thanks to Matt OP and \nLeonie for their wonderful notebooks.**","metadata":{}},{"cell_type":"markdown","source":"If you find it helpful, please do upvote it. :)","metadata":{}}]}