{"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":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import r2_score, mean_squared_error\nfrom sklearn.model_selection import GridSearchCV","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:24:46.148645Z","iopub.execute_input":"2022-10-26T22:24:46.149034Z","iopub.status.idle":"2022-10-26T22:24:46.764233Z","shell.execute_reply.started":"2022-10-26T22:24:46.148942Z","shell.execute_reply":"2022-10-26T22:24:46.763084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfor 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-10-26T22:24:46.772956Z","iopub.execute_input":"2022-10-26T22:24:46.773250Z","iopub.status.idle":"2022-10-26T22:24:46.779921Z","shell.execute_reply.started":"2022-10-26T22:24:46.773221Z","shell.execute_reply":"2022-10-26T22:24:46.778602Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019 = pd.read_csv('/kaggle/input/big-data-derby-2022/nyra_2019_complete.csv', low_memory=False, delimiter=',',\n                 names=['track_id', 'race_date', 'race_number', 'program_number', 'trakus_index', 'latitude',\n                        'longitude', 'distance_id', 'course_type', 'track_condition', 'run_up_distance', 'race_type',\n                        'purse', 'post_type', 'weight_carried', 'jockey', 'odds', 'position_at_finish'])","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:24:46.788368Z","iopub.execute_input":"2022-10-26T22:24:46.788801Z","iopub.status.idle":"2022-10-26T22:24:58.445958Z","shell.execute_reply.started":"2022-10-26T22:24:46.788754Z","shell.execute_reply":"2022-10-26T22:24:58.444899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019['race_date'] = pd.to_datetime(nyra_2019['race_date'])\nnyra_2019['month'] = nyra_2019['race_date'].dt.month\nnyra_2019 = nyra_2019.astype({'program_number': object, 'trakus_index': int, 'latitude': float,\n                'longitude': float, 'distance_id': int, 'course_type': object, 'track_condition': object,\n                'run_up_distance': int, 'race_type': object,\n                'post_type': object, 'weight_carried': int, 'jockey': object, 'odds': int, 'position_at_finish': int})","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:24:58.451338Z","iopub.execute_input":"2022-10-26T22:24:58.451635Z","iopub.status.idle":"2022-10-26T22:25:01.076359Z","shell.execute_reply.started":"2022-10-26T22:24:58.451604Z","shell.execute_reply":"2022-10-26T22:25:01.075378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019['odds'] = nyra_2019['odds']/100","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:01.081594Z","iopub.execute_input":"2022-10-26T22:25:01.082044Z","iopub.status.idle":"2022-10-26T22:25:01.123820Z","shell.execute_reply.started":"2022-10-26T22:25:01.081976Z","shell.execute_reply":"2022-10-26T22:25:01.122919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:01.136961Z","iopub.execute_input":"2022-10-26T22:25:01.138002Z","iopub.status.idle":"2022-10-26T22:25:01.164827Z","shell.execute_reply.started":"2022-10-26T22:25:01.137948Z","shell.execute_reply":"2022-10-26T22:25:01.163792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"nyra_2019.info()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:01.166246Z","iopub.execute_input":"2022-10-26T22:25:01.166694Z","iopub.status.idle":"2022-10-26T22:25:01.179619Z","shell.execute_reply.started":"2022-10-26T22:25:01.166651Z","shell.execute_reply":"2022-10-26T22:25:01.178590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:01.181345Z","iopub.execute_input":"2022-10-26T22:25:01.181669Z","iopub.status.idle":"2022-10-26T22:25:02.769088Z","shell.execute_reply.started":"2022-10-26T22:25:01.181607Z","shell.execute_reply":"2022-10-26T22:25:02.767802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nyra_2019.describe()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:02.770300Z","iopub.execute_input":"2022-10-26T22:25:02.770660Z","iopub.status.idle":"2022-10-26T22:25:06.047646Z","shell.execute_reply.started":"2022-10-26T22:25:02.770625Z","shell.execute_reply":"2022-10-26T22:25:06.046898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(16,16))\nsns.heatmap(nyra_2019.corr(), annot=True, cmap='Greens')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:06.048993Z","iopub.execute_input":"2022-10-26T22:25:06.049533Z","iopub.status.idle":"2022-10-26T22:25:08.999742Z","shell.execute_reply.started":"2022-10-26T22:25:06.049503Z","shell.execute_reply":"2022-10-26T22:25:08.998857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.set_option('display.max_rows', None)\npd.set_option('display.max_columns', None)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:09.000928Z","iopub.execute_input":"2022-10-26T22:25:09.001328Z","iopub.status.idle":"2022-10-26T22:25:09.007215Z","shell.execute_reply.started":"2022-10-26T22:25:09.001289Z","shell.execute_reply":"2022-10-26T22:25:09.006025Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sort_by_track_conditions = nyra_2019.groupby(['course_type','track_condition', 'jockey', 'position_at_finish'])['position_at_finish'].count().unstack('jockey').fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:09.008631Z","iopub.execute_input":"2022-10-26T22:25:09.009093Z","iopub.status.idle":"2022-10-26T22:25:10.677709Z","shell.execute_reply.started":"2022-10-26T22:25:09.009061Z","shell.execute_reply":"2022-10-26T22:25:10.676581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sort_by_track_conditions","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:10.679096Z","iopub.execute_input":"2022-10-26T22:25:10.679603Z","iopub.status.idle":"2022-10-26T22:25:13.390098Z","shell.execute_reply.started":"2022-10-26T22:25:10.679564Z","shell.execute_reply":"2022-10-26T22:25:13.388877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# AQU","metadata":{}},{"cell_type":"code","source":"pd.crosstab(nyra_2019['track_id'], nyra_2019['race_date'])","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:13.391560Z","iopub.execute_input":"2022-10-26T22:25:13.392345Z","iopub.status.idle":"2022-10-26T22:25:14.530971Z","shell.execute_reply.started":"2022-10-26T22:25:13.392299Z","shell.execute_reply":"2022-10-26T22:25:14.529771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.crosstab(nyra_2019['track_id'], nyra_2019['course_type'])","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:14.532511Z","iopub.execute_input":"2022-10-26T22:25:14.532868Z","iopub.status.idle":"2022-10-26T22:25:15.925226Z","shell.execute_reply.started":"2022-10-26T22:25:14.532835Z","shell.execute_reply":"2022-10-26T22:25:15.924146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track = nyra_2019.loc[nyra_2019['track_id']=='AQU']","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:15.926981Z","iopub.execute_input":"2022-10-26T22:25:15.927319Z","iopub.status.idle":"2022-10-26T22:25:16.633100Z","shell.execute_reply.started":"2022-10-26T22:25:15.927279Z","shell.execute_reply":"2022-10-26T22:25:16.631953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_January = AQU_track.loc[AQU_track['month']==1]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_January, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race in January')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:16.634459Z","iopub.execute_input":"2022-10-26T22:25:16.634761Z","iopub.status.idle":"2022-10-26T22:25:30.578395Z","shell.execute_reply.started":"2022-10-26T22:25:16.634710Z","shell.execute_reply":"2022-10-26T22:25:30.577503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_February = AQU_track.loc[AQU_track['month']==2]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_February, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race in February')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:30.579428Z","iopub.execute_input":"2022-10-26T22:25:30.579778Z","iopub.status.idle":"2022-10-26T22:25:45.545816Z","shell.execute_reply.started":"2022-10-26T22:25:30.579735Z","shell.execute_reply":"2022-10-26T22:25:45.544657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_March = AQU_track.loc[AQU_track['month']==3]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_March, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race in March')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:25:45.547466Z","iopub.execute_input":"2022-10-26T22:25:45.548164Z","iopub.status.idle":"2022-10-26T22:26:00.816996Z","shell.execute_reply.started":"2022-10-26T22:25:45.548124Z","shell.execute_reply":"2022-10-26T22:26:00.816166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_April = AQU_track.loc[AQU_track['month']==4]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_April, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race in April')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:26:00.818514Z","iopub.execute_input":"2022-10-26T22:26:00.818964Z","iopub.status.idle":"2022-10-26T22:26:14.192405Z","shell.execute_reply.started":"2022-10-26T22:26:00.818932Z","shell.execute_reply":"2022-10-26T22:26:14.188815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_November = AQU_track.loc[AQU_track['month']==11]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_November, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race in November')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:26:14.194142Z","iopub.execute_input":"2022-10-26T22:26:14.195241Z","iopub.status.idle":"2022-10-26T22:26:40.686295Z","shell.execute_reply.started":"2022-10-26T22:26:14.195195Z","shell.execute_reply":"2022-10-26T22:26:40.685227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_December = AQU_track.loc[AQU_track['month']==12]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_December, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race in December')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:26:40.687663Z","iopub.execute_input":"2022-10-26T22:26:40.687992Z","iopub.status.idle":"2022-10-26T22:26:59.439136Z","shell.execute_reply.started":"2022-10-26T22:26:40.687962Z","shell.execute_reply":"2022-10-26T22:26:59.437942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_Dirt = AQU_track.loc[AQU_track['course_type']=='D']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_Dirt, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race on Dirt')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:26:59.440340Z","iopub.execute_input":"2022-10-26T22:26:59.440703Z","iopub.status.idle":"2022-10-26T22:28:20.044876Z","shell.execute_reply.started":"2022-10-26T22:26:59.440672Z","shell.execute_reply":"2022-10-26T22:28:20.043662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_Outer_turf = AQU_track.loc[AQU_track['course_type']=='O']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_Outer_turf, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU))The trajectories of horses provided the race on Outer turf')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:28:20.046303Z","iopub.execute_input":"2022-10-26T22:28:20.046754Z","iopub.status.idle":"2022-10-26T22:28:29.786142Z","shell.execute_reply.started":"2022-10-26T22:28:20.046697Z","shell.execute_reply":"2022-10-26T22:28:29.785325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_track_Turf = AQU_track.loc[AQU_track['course_type']=='T']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=AQU_track_Turf, y='latitude', x='longitude', hue='program_number')\nplt.title('(AQU)The trajectories of horses provided the race on Turf')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:28:29.787397Z","iopub.execute_input":"2022-10-26T22:28:29.788278Z","iopub.status.idle":"2022-10-26T22:28:40.591738Z","shell.execute_reply.started":"2022-10-26T22:28:29.788243Z","shell.execute_reply":"2022-10-26T22:28:40.590895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As you can see, races were held at different distances in April, November and December. At the end is presented there is a table that shows which horse has won prizes how many times. By comparing the data, we can get the optimal trajectory in order to take the highest possible prize at the finish. We can also see which trajectory was optimal for different types of coverage and month","metadata":{}},{"cell_type":"markdown","source":"# BEL","metadata":{}},{"cell_type":"code","source":"BEL_track = nyra_2019.loc[nyra_2019['track_id']=='BEL']","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:28:40.592928Z","iopub.execute_input":"2022-10-26T22:28:40.593752Z","iopub.status.idle":"2022-10-26T22:28:41.291542Z","shell.execute_reply.started":"2022-10-26T22:28:40.593702Z","shell.execute_reply":"2022-10-26T22:28:41.290337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_May = BEL_track.loc[BEL_track['month']==5]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_May, x='longitude', y='latitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race in May')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:28:41.292823Z","iopub.execute_input":"2022-10-26T22:28:41.293129Z","iopub.status.idle":"2022-10-26T22:29:01.581570Z","shell.execute_reply.started":"2022-10-26T22:28:41.293101Z","shell.execute_reply":"2022-10-26T22:29:01.580445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_June = BEL_track.loc[BEL_track['month']==6]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_June, x='longitude', y='latitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race in June')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:29:01.583054Z","iopub.execute_input":"2022-10-26T22:29:01.583396Z","iopub.status.idle":"2022-10-26T22:29:22.412382Z","shell.execute_reply.started":"2022-10-26T22:29:01.583366Z","shell.execute_reply":"2022-10-26T22:29:22.411400Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_July = BEL_track.loc[BEL_track['month']==7]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_July, x='longitude', y='latitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race in July')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:29:22.413992Z","iopub.execute_input":"2022-10-26T22:29:22.414300Z","iopub.status.idle":"2022-10-26T22:29:28.257087Z","shell.execute_reply.started":"2022-10-26T22:29:22.414271Z","shell.execute_reply":"2022-10-26T22:29:28.256081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_September = BEL_track.loc[BEL_track['month']==9]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_September, x='longitude', y='latitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race in September')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:29:28.258350Z","iopub.execute_input":"2022-10-26T22:29:28.258676Z","iopub.status.idle":"2022-10-26T22:29:47.300480Z","shell.execute_reply.started":"2022-10-26T22:29:28.258647Z","shell.execute_reply":"2022-10-26T22:29:47.299615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_October = BEL_track.loc[BEL_track['month']==10]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_October, x='longitude', y='latitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race in October')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:29:47.301756Z","iopub.execute_input":"2022-10-26T22:29:47.302226Z","iopub.status.idle":"2022-10-26T22:30:06.033466Z","shell.execute_reply.started":"2022-10-26T22:29:47.302195Z","shell.execute_reply":"2022-10-26T22:30:06.032561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_Dirt = BEL_track.loc[BEL_track['course_type']=='D']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_Dirt, y='latitude', x='longitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race on Dirt')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:30:06.034947Z","iopub.execute_input":"2022-10-26T22:30:06.036085Z","iopub.status.idle":"2022-10-26T22:30:45.910746Z","shell.execute_reply.started":"2022-10-26T22:30:06.036044Z","shell.execute_reply":"2022-10-26T22:30:45.909908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_Hurdle = BEL_track.loc[BEL_track['course_type']=='M']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_Hurdle, y='latitude', x='longitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race on Hurdle')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:30:45.917493Z","iopub.execute_input":"2022-10-26T22:30:45.917835Z","iopub.status.idle":"2022-10-26T22:30:47.377844Z","shell.execute_reply.started":"2022-10-26T22:30:45.917805Z","shell.execute_reply":"2022-10-26T22:30:47.376649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_Inner_turf = BEL_track.loc[BEL_track['course_type']=='I']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_Inner_turf, y='latitude', x='longitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race on Inner turf')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:30:47.379354Z","iopub.execute_input":"2022-10-26T22:30:47.379760Z","iopub.status.idle":"2022-10-26T22:31:08.951045Z","shell.execute_reply.started":"2022-10-26T22:30:47.379703Z","shell.execute_reply":"2022-10-26T22:31:08.950021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_track_turf = BEL_track.loc[BEL_track['course_type']=='T']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=BEL_track_turf, y='latitude', x='longitude', hue='program_number')\nplt.title('(BEL)The trajectories of horses provided the race on Turf')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:31:08.952336Z","iopub.execute_input":"2022-10-26T22:31:08.952635Z","iopub.status.idle":"2022-10-26T22:31:32.375115Z","shell.execute_reply.started":"2022-10-26T22:31:08.952608Z","shell.execute_reply":"2022-10-26T22:31:32.374107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"On this track, we performed all the same operations as on the AQU. We see that races at different distances took place on this track every month, as well as the fact that there was a different type of track coverage for each distance, as evidenced by the comparison of the schedules of horse races on tracks with different coverage and the schedule of the race in any month","metadata":{}},{"cell_type":"markdown","source":"# SAR","metadata":{}},{"cell_type":"code","source":"SAR_track = nyra_2019.loc[nyra_2019['track_id']=='SAR']","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:31:32.376376Z","iopub.execute_input":"2022-10-26T22:31:32.377273Z","iopub.status.idle":"2022-10-26T22:31:32.910254Z","shell.execute_reply.started":"2022-10-26T22:31:32.377230Z","shell.execute_reply":"2022-10-26T22:31:32.909141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_July = SAR_track.loc[SAR_track['month']==7]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_July, x='longitude', y='latitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race in July')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:31:32.911636Z","iopub.execute_input":"2022-10-26T22:31:32.911990Z","iopub.status.idle":"2022-10-26T22:31:51.978933Z","shell.execute_reply.started":"2022-10-26T22:31:32.911959Z","shell.execute_reply":"2022-10-26T22:31:51.977787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_August = SAR_track.loc[SAR_track['month']==8]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_August, x='longitude', y='latitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race in August')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:31:51.980650Z","iopub.execute_input":"2022-10-26T22:31:51.981006Z","iopub.status.idle":"2022-10-26T22:32:23.564338Z","shell.execute_reply.started":"2022-10-26T22:31:51.980974Z","shell.execute_reply":"2022-10-26T22:32:23.563524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_September = SAR_track.loc[SAR_track['month']==8]\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_September, x='longitude', y='latitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race in September')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:32:23.565783Z","iopub.execute_input":"2022-10-26T22:32:23.566304Z","iopub.status.idle":"2022-10-26T22:32:55.216605Z","shell.execute_reply.started":"2022-10-26T22:32:23.566271Z","shell.execute_reply":"2022-10-26T22:32:55.215437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_turf = SAR_track.loc[SAR_track['course_type']=='T']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_turf, y='latitude', x='longitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race on Turf')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:32:55.217915Z","iopub.execute_input":"2022-10-26T22:32:55.218232Z","iopub.status.idle":"2022-10-26T22:33:07.119182Z","shell.execute_reply.started":"2022-10-26T22:32:55.218202Z","shell.execute_reply":"2022-10-26T22:33:07.117827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_Inner_turf = SAR_track.loc[SAR_track['course_type']=='I']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_Inner_turf, y='latitude', x='longitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race on Inner turf')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:07.120681Z","iopub.execute_input":"2022-10-26T22:33:07.121428Z","iopub.status.idle":"2022-10-26T22:33:20.124128Z","shell.execute_reply.started":"2022-10-26T22:33:07.121380Z","shell.execute_reply":"2022-10-26T22:33:20.123039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_Dirt = SAR_track.loc[SAR_track['course_type']=='D']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_Dirt, y='latitude', x='longitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race on Dirt')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:20.125900Z","iopub.execute_input":"2022-10-26T22:33:20.126586Z","iopub.status.idle":"2022-10-26T22:33:46.643992Z","shell.execute_reply.started":"2022-10-26T22:33:20.126541Z","shell.execute_reply":"2022-10-26T22:33:46.642908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_track_Hurdle = SAR_track.loc[SAR_track['course_type']=='M']\nplt.figure(figsize=(16,16))\nsns.scatterplot(data=SAR_track_Hurdle, y='latitude', x='longitude', hue='program_number')\nplt.title('(SAR)The trajectories of horses provided the race on Hurdle')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:46.645710Z","iopub.execute_input":"2022-10-26T22:33:46.646212Z","iopub.status.idle":"2022-10-26T22:33:49.602265Z","shell.execute_reply.started":"2022-10-26T22:33:46.646160Z","shell.execute_reply":"2022-10-26T22:33:49.601046Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As well as on the previous two tracks, there were races at different distances. we have plotted trajectories depending on the month and the type of soil","metadata":{}},{"cell_type":"code","source":"nyra_2019.groupby(['track_id','program_number','position_at_finish', 'month'])['position_at_finish'].count().unstack('position_at_finish').fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:49.603680Z","iopub.execute_input":"2022-10-26T22:33:49.604025Z","iopub.status.idle":"2022-10-26T22:33:51.102840Z","shell.execute_reply.started":"2022-10-26T22:33:49.603994Z","shell.execute_reply":"2022-10-26T22:33:51.101769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In the intervals of the following coordinates, frequent emissions are observed on the AQU track, perhaps this is due to any falls of horses, or participants leaving the track. It is recommended to examine this section of the route and take measures to ensure the safety of this section. No emissions have been noticed on the BELL and SAR tracks, there may be fewer horse injuries there.\n\nLatitude 40.4718 40.674\nLongitute -73.8312 -73.8308","metadata":{}},{"cell_type":"markdown","source":"# Preparing data for the ML model","metadata":{}},{"cell_type":"markdown","source":"course_type\nM - Hurdle - 1\nD - Dirt - 2\nO - Outer turf - 3\nI - Inner turf - 4\nT - turf - 5","metadata":{}},{"cell_type":"markdown","source":"track_condition\nYL - Yielding - 1\nFM - Firm - 2\nSY - Sloppy - 3 \nGD - Good - 4\nFT - Fast - 5\nMY - Muddy - 6\nSF - Soft - 7","metadata":{}},{"cell_type":"markdown","source":"race_type\nSTK - Stakes 1\nWCL - Waiver Claiming 2\nWMC - Waiver Maiden Claiming 3\nSST - Starter Stakes 4\nSHP - Starter Handicap 5\nCLM - Claiming 6\nSTR - Starter Allowance 7\nAOC - Allowance Optionl Claimer 8\nSOC - Starter Optional Claimer 9\nMCL - Maiden Claiming 10\nALW - Allowance 11\nMSW - Maiden Special Weight 12","metadata":{}},{"cell_type":"code","source":"df_for_model = nyra_2019.iloc[:,8:]","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:51.104598Z","iopub.execute_input":"2022-10-26T22:33:51.105336Z","iopub.status.idle":"2022-10-26T22:33:51.487942Z","shell.execute_reply.started":"2022-10-26T22:33:51.105293Z","shell.execute_reply":"2022-10-26T22:33:51.487082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_for_model.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:51.489321Z","iopub.execute_input":"2022-10-26T22:33:51.489955Z","iopub.status.idle":"2022-10-26T22:33:51.510457Z","shell.execute_reply.started":"2022-10-26T22:33:51.489901Z","shell.execute_reply":"2022-10-26T22:33:51.509607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_for_model['course_type'] = df_for_model['course_type'].replace({'M' : 1, 'D' : 2, 'O' : 3, 'I' : 4, 'T' : 5})\ndf_for_model['track_condition'] = df_for_model['track_condition'].replace({'YL ' : 1, 'FM ' : 2, 'SY ' : 3, 'GD ' : 4, 'FT ' : 5, 'MY ' : 6, 'SF ' : 7})\ndf_for_model['race_type'] = df_for_model['race_type'].replace({'STK' : 1, 'WCL' : 2, 'WMC' : 3, 'SST' : 4, 'SHP' : 5, 'CLM' : 6, 'STR' : 7, 'AOC' : 8, 'SOC' : 9, 'MCL' : 10, 'ALW' : 11, 'MSW' : 12})","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:33:51.511672Z","iopub.execute_input":"2022-10-26T22:33:51.512047Z","iopub.status.idle":"2022-10-26T22:34:01.526549Z","shell.execute_reply.started":"2022-10-26T22:33:51.512009Z","shell.execute_reply":"2022-10-26T22:34:01.525520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_for_model.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:34:01.527935Z","iopub.execute_input":"2022-10-26T22:34:01.528383Z","iopub.status.idle":"2022-10-26T22:34:01.545920Z","shell.execute_reply.started":"2022-10-26T22:34:01.528331Z","shell.execute_reply":"2022-10-26T22:34:01.544746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_for_model['jockey'] = df_for_model['jockey'].replace({'Andre Shivnarine Worrie':1, 'Manuel Franco':2, 'Dylan Davis':3,\n       'Irad Ortiz Jr.':4, 'Samuel Jimenez':5, 'Heman K. Harkie':6,\n       'Joey R. Martinez':7, 'Rajiv Maragh':8, 'Reylu Gutierrez':9,\n       'Jose L. Ortiz':10, 'Silvestre Gonzalez':11, 'Junior Alvarado':12,\n       'Gerard Galligan':13, 'Jack Doyle':14, 'Victor R. Carrasco':15,\n       'Benjamin Hernandez':16, 'Hector Rafael Diaz Jr.':17, 'Eric Cancel':18,\n       'Oscar Gomez':19, 'Jorge A. Vargas Jr.':20, 'Joel Rosario':21,\n       'Carlos J. Hernandez':22, 'Michael J. Luzzi':23,\n       'Rafael Manuel Hernandez':24, 'Luis R. Reyes':25, 'Jose A. Bracho':26,\n       'Jose Lezcano':27, 'Luis A. Rodriguez Castro':28, 'Samuel Camacho Jr.':29,\n       'Danny Mullins':30, 'Kendrick Carmouche':31, 'Ruben Silvera':32,\n       'Emmanuel Esquivel':33, 'Dalton Brown':34, 'Ricardo Santana Jr.':35,\n       'Sean McDermott':36, 'Michael Mitchell':37, 'Julio Correa':38,\n       'Keivan Serrano':39, 'Harry Hernandez':40, 'Luis Saez':41, 'Joe Bravo':42,\n       'John R. Velazquez':43, 'Ross Geraghty':44, 'David Cohen':45,\n       'Javier Castellano':46, 'Tyler Gaffalione':47, 'Jevian Toledo':48,\n       'Wilmer A. Garcia':49, 'Jose Baez':50, 'Chris Landeros':51,\n       'Winston R. Kay':52, 'Joel Sone':53, 'Paco Lopez':54, 'Gary Richards':55,\n       'Kirk Johnson':56, 'Julien R. Leparoux':57, 'Channing Hill':58,\n       'Jorge M. Perez':59, 'Nik Juarez':60, 'Sheldon Russell':61, 'Kevin Carmona':62,\n       'Vince Halliday':63, 'John Bisono':64, 'Emisael Jaramillo':65,\n       'J. D. Acosta':66, 'Mike E. Smith':67, 'Erick Lopez':68, 'Carol Cedeno':69,\n       'Christopher P. DeCarlo':70, 'Corey J. Lanerie':71, 'Declan Carroll':72,\n       'Jorge Ruiz':73, 'William McCarthy':74, 'Miguel A. Melendez':75,\n       'Talbert Howell':76, 'Nazario Alvarado':77, 'Christian Santiago Reyes':78,\n       'Edward Escobar':79, 'Flavien Prat':80, 'Kevin Gomez':81, 'Jose F. Rojas':82,\n       'Katie Davis':83, 'Julian Pimentel':84, 'Pablo Fragoso':85,\n       'Jeremias Flores':86, 'Feargal Lynch':87, 'Bernard Dalton':88,\n       'Jose C. Ferrer':89, 'Kieran Norris':90, 'Dyn Panell':91, 'Leonardo Corujo':92,\n       'Edwin Rivera':93, 'Tzeonn Chang':94, 'Jaime Rodriguez':95,\n       'Georgina Sergeon':96, 'Jomar Torres':97, 'Trevor McCarthy':98,\n       'Tyler Conner':99, 'Richard A. Bracho':100, 'Adam Beschizza':101,\n       'Steven Ronald Bahen':102, 'Barry Foley':103, 'Cristina Bonilla':104,\n       'Mario Gutierrez':105, 'Johan Rosado':106, 'Charles C. Lopez':107,\n       'Jomar Garcia':108, 'Frankie Pennington':109, 'Angel R. Rodriguez':110,\n       'Florent Geroux':111, 'Robbie G. Davis':112, 'Mark Watts':113, 'Tyler Baze':114,\n       'Kody Kellenberger':115, 'Tammi Piermarini':116, 'Anthony Salgado':117,\n       'Weston Hamilton':118, 'Alex Cintron':119, 'Joseph Talamo':120,\n       'Jose Angel Garcia':121, 'Grant Whitacre':122, 'Luis Cardenas':123,\n       'Gavin Coetzee':124, 'Mychel J. Sanchez':125, 'Tomas B. Mejia':126,\n       'Daniel Centeno':127, 'Jeremy Rose':128, 'Andrea C. Rodriguez':129,\n       'Charlie Amaro':130, 'Emanuel De Diego':131, 'Abner Adorno':132, 'Arienne Cox':133,\n       'Sophie Doyle':134, 'Shaun Bridgmohan':135, 'Andrew Wolfsont':136,\n       'Leonel Reyes':137, 'Cory Orm':138, 'Victor Espinoza':139, 'Angel Castillo':140,\n       'Adam Bowman':141, 'Martin Chuan':142, 'Navin Mangalee':143, 'Declan Cannon':144,\n       'Dana G. Whitney':145, 'Forest Boyce':146, 'Wayne Lordan':147,\n       'Jose R. Betancourt':148, 'Jamie P. Spencer':149, 'Jeffrey Sanchez':150,\n       'Adrian Flores':151, 'Rosario Montanez':152, 'Jorge L. Vargas Jr.':153,\n       'Antonio A. Gallardo':154, 'Shannon Uske':155, 'Nathan Vickers':156,\n       'Jose Antonio Gallego':157, 'Brian Joseph Hernandez Jr.':158, 'Angel Cruz':159,\n       'Daisuke Fukumoto':160, 'Miyabi Muto':161, 'Angel Suarez':162,\n       'Virginia Tormey':163, 'Luca Panici':164, 'Graham Watters':165,\n       'Edgar S. Prado':166, 'Darren Nagle':167, 'Christophe Soumillon':168,\n       'Michael Hussey':169, 'Rachael Blackmore':170, 'Suguru Hamanaka':171,\n       'Thomas Garner':172, 'Ben Curtis':173, 'Jozef Bojko':174, 'Andrea Atzeni':175,\n       'Stephane Pasquier':176, 'Sam Twiston-Davies':177, 'Tony Piccone':178})","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:34:01.547312Z","iopub.execute_input":"2022-10-26T22:34:01.547627Z","iopub.status.idle":"2022-10-26T22:34:36.326200Z","shell.execute_reply.started":"2022-10-26T22:34:01.547598Z","shell.execute_reply":"2022-10-26T22:34:36.324941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df_for_model['position_at_finish']\nX = df_for_model.drop(['position_at_finish', 'purse', 'post_type'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:34:36.327454Z","iopub.execute_input":"2022-10-26T22:34:36.327820Z","iopub.status.idle":"2022-10-26T22:34:36.691452Z","shell.execute_reply.started":"2022-10-26T22:34:36.327788Z","shell.execute_reply":"2022-10-26T22:34:36.690027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:34:36.692972Z","iopub.execute_input":"2022-10-26T22:34:36.693347Z","iopub.status.idle":"2022-10-26T22:34:37.893596Z","shell.execute_reply.started":"2022-10-26T22:34:36.693312Z","shell.execute_reply":"2022-10-26T22:34:37.892391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ML model for the to predict a possible place at the finish line","metadata":{}},{"cell_type":"code","source":"RFR = RandomForestRegressor(max_depth=22,min_samples_leaf=3, random_state=3)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:34:37.895977Z","iopub.execute_input":"2022-10-26T22:34:37.896298Z","iopub.status.idle":"2022-10-26T22:34:37.902107Z","shell.execute_reply.started":"2022-10-26T22:34:37.896268Z","shell.execute_reply":"2022-10-26T22:34:37.901216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"RFR.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:34:37.903435Z","iopub.execute_input":"2022-10-26T22:34:37.904010Z","iopub.status.idle":"2022-10-26T22:52:28.211535Z","shell.execute_reply.started":"2022-10-26T22:34:37.903977Z","shell.execute_reply":"2022-10-26T22:52:28.210150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_train = RFR.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:52:28.212961Z","iopub.execute_input":"2022-10-26T22:52:28.213264Z","iopub.status.idle":"2022-10-26T22:54:09.268268Z","shell.execute_reply.started":"2022-10-26T22:52:28.213236Z","shell.execute_reply":"2022-10-26T22:54:09.267216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test = RFR.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:54:09.269591Z","iopub.execute_input":"2022-10-26T22:54:09.269941Z","iopub.status.idle":"2022-10-26T22:54:34.407837Z","shell.execute_reply.started":"2022-10-26T22:54:09.269912Z","shell.execute_reply":"2022-10-26T22:54:34.407047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MSE_train = mean_squared_error(y_train, pred_train)\nRMSE_train = mean_squared_error(y_train, pred_train, squared=False)\nR2_train = r2_score(y_train, pred_train)\nMSE_test = mean_squared_error(y_test, pred_test)\nRMSE_test = mean_squared_error(y_test, pred_test, squared=False)\nR2_test = r2_score(y_test, pred_test)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:54:34.408836Z","iopub.execute_input":"2022-10-26T22:54:34.409789Z","iopub.status.idle":"2022-10-26T22:54:34.511870Z","shell.execute_reply.started":"2022-10-26T22:54:34.409756Z","shell.execute_reply":"2022-10-26T22:54:34.510992Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\n    f'(MSE) Metric on the training sample:{round(MSE_train, 2)}\\n(MSE) Metric on the testing sample:{round(MSE_test, 2)}\\n'\n    f'(R2) Metric on the training sample:{round(R2_train, 2)}\\n(R2) Metric on the testing sample:{round(R2_test, 2)}\\n'\n    f'(RMSE) Metric on the training sample:{round(RMSE_train, 2)}\\n(RMSE) Metric on the testing sample:{round(RMSE_test, 2)}')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:54:34.513362Z","iopub.execute_input":"2022-10-26T22:54:34.513684Z","iopub.status.idle":"2022-10-26T22:54:34.520933Z","shell.execute_reply.started":"2022-10-26T22:54:34.513652Z","shell.execute_reply":"2022-10-26T22:54:34.519464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GBR = GradientBoostingRegressor(max_depth = 13,max_features = 4,random_state=2, min_samples_leaf=2, learning_rate = 0.1)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:54:34.522227Z","iopub.execute_input":"2022-10-26T22:54:34.522503Z","iopub.status.idle":"2022-10-26T22:54:34.535239Z","shell.execute_reply.started":"2022-10-26T22:54:34.522476Z","shell.execute_reply":"2022-10-26T22:54:34.534364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GBR.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T22:54:34.536567Z","iopub.execute_input":"2022-10-26T22:54:34.537181Z","iopub.status.idle":"2022-10-26T23:11:50.495124Z","shell.execute_reply.started":"2022-10-26T22:54:34.537148Z","shell.execute_reply":"2022-10-26T23:11:50.494013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_train_GBR = GBR.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T23:11:50.496275Z","iopub.execute_input":"2022-10-26T23:11:50.496575Z","iopub.status.idle":"2022-10-26T23:12:30.588159Z","shell.execute_reply.started":"2022-10-26T23:11:50.496545Z","shell.execute_reply":"2022-10-26T23:12:30.587069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test_GBR = GBR.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T23:12:30.589774Z","iopub.execute_input":"2022-10-26T23:12:30.590330Z","iopub.status.idle":"2022-10-26T23:12:40.595840Z","shell.execute_reply.started":"2022-10-26T23:12:30.590296Z","shell.execute_reply":"2022-10-26T23:12:40.594773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"MSE_train_GBR = mean_squared_error(y_train,pred_train_GBR)\nRMSE_train_GBR = mean_squared_error(y_train, pred_train_GBR, squared=False)\nR2_train_GBR = r2_score(y_train, pred_train_GBR)\nMSE_test_GBR = mean_squared_error(y_test, pred_test_GBR)\nRMSE_test_GBR = mean_squared_error(y_test, pred_test_GBR, squared=False)\nR2_test_GBR = r2_score(y_test, pred_test_GBR)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T23:12:40.596917Z","iopub.execute_input":"2022-10-26T23:12:40.597209Z","iopub.status.idle":"2022-10-26T23:12:40.700138Z","shell.execute_reply.started":"2022-10-26T23:12:40.597181Z","shell.execute_reply":"2022-10-26T23:12:40.699132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\n    f'(MSE) Metric on the training sample:{round(MSE_train_GBR, 2)}\\n(MSE) Metric on the testing sample:{round(MSE_test_GBR, 2)}\\n'\n    f'(R2) Metric on the training sample:{round(R2_train_GBR, 2)}\\n(R2) Metric on the testing sample:{round(R2_test_GBR, 2)}\\n'\n    f'(RMSE) Metric on the training sample:{round(RMSE_train_GBR, 2)}\\n(RMSE) Metric on the testing sample:{round(RMSE_test_GBR, 2)}')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T23:12:40.701614Z","iopub.execute_input":"2022-10-26T23:12:40.701985Z","iopub.status.idle":"2022-10-26T23:12:40.707627Z","shell.execute_reply.started":"2022-10-26T23:12:40.701952Z","shell.execute_reply":"2022-10-26T23:12:40.706879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Two ML models have been compiled for approximate prediction of a place at the finish line, depending on various parameters (course_type, track_condition, run_up_distance, race_type, weight_carried, jockey, odds)","metadata":{}}]}