{"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":" **Our approach in obtaining individual information for each race that can be further applied to a predictive model**\n - \n ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-10T17:26:39.747958Z","iopub.execute_input":"2022-11-10T17:26:39.748425Z","iopub.status.idle":"2022-11-10T17:26:41.471737Z","shell.execute_reply.started":"2022-11-10T17:26:39.748329Z","shell.execute_reply":"2022-11-10T17:26:41.470848Z"}}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport torch\nimport torch.nn as nn\nfrom torch.utils.data.sampler import SubsetRandomSampler\n","metadata":{"execution":{"iopub.status.busy":"2022-11-10T18:07:58.587980Z","iopub.execute_input":"2022-11-10T18:07:58.588394Z","iopub.status.idle":"2022-11-10T18:07:58.593103Z","shell.execute_reply.started":"2022-11-10T18:07:58.588361Z","shell.execute_reply":"2022-11-10T18:07:58.592328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**First thing on the business order was to decide in which direction to go with this project, thus, we decided to do a simple, yet probably most relevant task for betting enthusiast: \" predict the podium of the race.**\n\n  First things first:\n\n a)**check the data:**(done)\n \n First we observed that we don't have the column with the finsihing place. We also observed that we had a lot of data from a single race, and the cause for this was the fact that each race information is quantified by the trakus_index. So, in other words, we had a big file with a whole lot of redundant data.\n It became pretty clear for us, that for working with this dataset, it needed to be simplified.\n \n \n b)**Simplify the dataset:**(done)\n  \n  In order to decide the relevance of each data-part we had to ask ourselves the following questions: when can we start betting? When does the betting end? What information do we have before the races to increase our chances? Are the given odds really that relevant for placing a good bet?\n  \n  \n c)**All numbers!!**(done)\n  \n  It was of great importance to mostly have numbers in the dataset, so the computer can help up as its best.\n  \n  \n d)**Deciding the approach**(done)\n \n \n e)**Implementation: two steps**(in progress)\n\n","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"\ncheck_data_df = pd.read_csv(\"../input/big-data-derby-2022/nyra_tracking_table.csv\" )\ncheck_data_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-10T18:20:56.522108Z","iopub.execute_input":"2022-11-10T18:20:56.522788Z","iopub.status.idle":"2022-11-10T18:21:04.187417Z","shell.execute_reply.started":"2022-11-10T18:20:56.522741Z","shell.execute_reply":"2022-11-10T18:21:04.186235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**We are interested to know:**\n - track_id: obviously the track influences the horse performance\n - race_date: we split the date in months, days and day-periods, because we believe that the usual schedule of training can be disturebed by the race. Also different breeds of horses have major preferances for the period of the race and the implied weather conditions \n - course_type\n - track_condition\n - weight_carried\n - jockey\n - horse\n - we also created a variable which keeps notice of past performances\n - odds","metadata":{}},{"cell_type":"code","source":"Converted_dataset = pd.read_csv(\"../input/derby2022-convertedcsv/Derby2022_Converted_Dataset.csv\")\nConverted_dataset.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-10T18:33:42.318043Z","iopub.execute_input":"2022-11-10T18:33:42.318508Z","iopub.status.idle":"2022-11-10T18:33:42.349566Z","shell.execute_reply.started":"2022-11-10T18:33:42.318468Z","shell.execute_reply":"2022-11-10T18:33:42.348426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We also decided to reshape the dataset, in a way, where every row contains information about every individual race, with following features:('race_id','track_id','race_number','distance_id','course_type','track_condition','run_up_distance',  'race_type','month','race_day_name','day_period') and it also contains information about the horses: (jokey','horse_id','weight_carried','finishing_place','performance','odds'). \n\nWe also observed that the races don't have the same amount of participating horse, so to deal with that we created some imaginary horses.\n\nIn the index of y column, we obtain the podium of the respective race, for example: [5,4,0] respresents that the horse with id = 5 won the race, id = 4 was second and etc...","metadata":{}},{"cell_type":"code","source":"#Conversion rules:\nDELTA_TIME = 0.25  # 0.25 second per trakus_index according to the data description.\n\nTRACK_ELEVATION = {\"AQU\": 3, \"BEL\": 20, \"SAR\": 93}  # Elevations obtained from Google Earth\nTRACK_NUMBER = {0: \"AQU\", 1: \"BEL\", 2: \"SAR\"}\nNUMBER_TRACK = {'AQU': \"0\", 'BEL':\"1\", 'SAR': \"2\"}\n\n# Data used to split day in moments:\nDAY_SPLIT = {'earliest': (1130, 1130), 'early_mid_day': (1130, 1259),\n             'mid_day': (501, 728), 'afternoon': (100, 459), 'last': (800, 800)}\nDAY_SPLIT_NUMBER = {1: 'earliest', 2: 'early_mid_day', 3: 'mid-day', 4: 'afternoon', 5: 'last'}\n\nDAY_NAME_TO_NUMBER = {'Monday': 1, 'Tuesday': 2, 'Wednesday': 3, 'Thursday': 4, 'Friday': 5, 'Saturday': 6, 'Sunday': 7}\nNUMBER_TO_DAY_NAME = {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 7: 'Sunday'}\n\n# course_type\nCOURSE_TYPE_TI_NUMBER = {'D': 0, 'O': 1, 'I': 2, 'T': 3, 'M': 4}\nNUMBER_TO_COURSE_TYPE = {0: 'D', 1: 'O', 2: 'I', 3: 'T', 4: 'M'}\n\n# track conditions\nTRACK_CONDITION_TO_NUMBER = {'GD ': 0, 'FM ': 1, 'FT ': 2, 'SY ': 3, 'MY ': 4, 'YL ': 5, 'SF ': 6}\nNUMBER_TO_TRACK_CONDITION = {0: 'GD ', 1: 'FM ', 2: 'FT ', 3: 'SY ', 4: 'MY ', 5: 'YL ', 6: 'SF '}\n\n# race type\nRACE_TYPE_TO_NUMBER = {'CLM': 0, 'AOC': 1, 'ALW': 2, 'SST': 3, 'STK': 4, 'WCL': 5, 'STR': 6,\n                       'SOC': 7, 'SHP': 8, 'MCL': 9, 'WMC': 10, 'MSW': 11}\nNUMBER_TO_RACE_TYPE = {0: 'CLM', 1: 'AOC', 2: 'ALW', 3: 'SST', 4: 'STK', 5: 'WCL', 6: 'STR',\n                       7: 'SOC', 8: 'SHP', 9: 'MCL', 10: 'WMC', 11: 'MSW'}\n\n# Jockey dictionary\nJOCKEY_TO_NUMBER = {'Andre Shivnarine Worrie': 0, 'Manuel Franco': 1, 'Dylan Davis': 2, 'Irad Ortiz Jr.': 3,\n                    'Jimenez': 4, 'Heman K. Harkie': 5, 'Joey R. Martinez': 6, 'Rajiv Maragh': 7, 'Reylu Gutierrez': 8,\n                    'Jose L. Ortiz': 9, 'Silvestre Gonzalez': 10, 'Junior Alvarado': 11, 'Gerard Galligan': 12,\n                    'Jack Doyle': 13, 'Victor R. Carrasco': 14, 'Benjamin Hernandez': 15, 'Hector Rafael Diaz Jr.': 16,\n                    'Eric Cancel': 17, 'Oscar Gomez': 18, 'Jorge A. Vargas Jr.': 19, 'Joel Rosario': 20,\n                    'Carlos J. Hernandez': 21, 'Michael J. Luzzi': 22, 'Rafael Manuel Hernandez': 23,\n                    'Luis R. Reyes': 24, 'Jose A. Bracho': 25, 'Jose Lezcano': 26, 'Luis A. Rodriguez Castro': 27,\n                    'Samuel Camacho Jr.': 28, 'Danny Mullins': 29, 'Kendrick Carmouche': 30, 'Ruben Silvera': 31,\n                    'Emmanuel Esquivel': 32, 'Dalton Brown': 33, 'Ricardo Santana Jr.': 34, 'Sean McDermott': 35,\n                    'Michael Mitchell': 36, 'Julio Correa': 37, 'Keivan Serrano': 38, 'Harry Hernandez': 39,\n                    'Luis Saez': 40, 'Joe Bravo': 41, 'John R. Velazquez': 42, 'Ross Geraghty': 43, 'David Cohen': 44,\n                    'Javier Castellano': 45, 'Tyler Gaffalione': 46, 'Jevian Toledo': 47, 'Wilmer A. Garcia': 48,\n                    'Jose Baez': 49, 'Chris Landeros': 50, 'Winston R. Kay': 51, 'Joel Sone': 52, 'Paco Lopez': 53,\n                    'Gary Richards': 54, 'Kirk Johnson': 55, 'Julien R. Leparoux': 56, 'Channing Hill': 57,\n                    'Jorge M. Perez': 58, 'Nik Juarez': 59, 'Sheldon Russell': 60, 'Kevin Carmona': 61,\n                    'Vince Halliday': 62, 'John Bisono': 63, 'Emisael Jaramillo': 64, 'J. D. Acosta': 65,\n                    'Mike E. Smith': 66, 'Erick Lopez': 67, 'Carol Cedeno': 68, 'Christopher P. DeCarlo': 69,\n                    'Corey J. Lanerie': 70, 'Declan Carroll': 71, 'Jorge Ruiz': 72, 'William McCarthy': 73,\n                    'Miguel A. Melendez': 74, 'Talbert Howell': 75, 'Nazario Alvarado': 76,\n                    'Christian Santiago Reyes': 77, 'Edward Escobar': 78, 'Flavien Prat': 79,\n                    'Kevin Gomez': 80, 'Jose F. Rojas': 81, 'Katie Davis': 82, 'Julian Pimentel': 83,\n                    'Pablo Fragoso': 84, 'Jeremias Flores': 85, 'Feargal Lynch': 86, 'Bernard Dalton': 87,\n                    'Jose C. Ferrer': 88, 'Kieran Norris': 89, 'Dyn Panell': 90, 'Leonardo Corujo': 91,\n                    'Edwin Rivera': 92, 'Tzeonn Chang': 93, 'Jaime Rodriguez': 94, 'Georgina Sergeon': 95,\n                    'Jomar Torres': 96, 'Trevor McCarthy': 97, 'Tyler Conner': 98, 'Richard A. Bracho': 99,\n                    'Adam Beschizza': 100, 'Steven Ronald Bahen': 101, 'Barry Foley': 102, 'Cristina Bonilla': 103,\n                    'Mario Gutierrez': 104, 'Johan Rosado': 105, 'Charles C. Lopez': 106, 'Jomar Garcia': 107,\n                    'Frankie Pennington': 108, 'Angel R. Rodriguez': 109, 'Florent Geroux': 110,\n                    'Robbie G. Davis': 111, 'Mark Watts': 112, 'Tyler Baze': 113, 'Kody Kellenberger': 114,\n                    'Tammi Piermarini': 115, 'Anthony Salgado': 116, 'Weston Hamilton': 117, 'Alex Cintron': 118,\n                    'Joseph Talamo': 119, 'Jose Angel Garcia': 120, 'Grant Whitacre': 121, 'Luis Cardenas': 122,\n                    'Gavin Coetzee': 123, 'Mychel J. Sanchez': 124, 'Tomas B. Mejia': 125, 'Daniel Centeno': 126,\n                    'Jeremy Rose': 127, 'Andrea C. Rodriguez': 128, 'Charlie Amaro': 129, 'Emanuel De Diego': 130,\n                    'Abner Adorno': 131, 'Arienne Cox': 132, 'Sophie Doyle': 133, 'Shaun Bridgmohan': 134,\n                    'Andrew Wolfsont': 135, 'Leonel Reyes': 136, 'Cory Orm': 137, 'Victor Espinoza': 138,\n                    'Angel Castillo': 139, 'Adam Bowman': 140, 'Martin Chuan': 141, 'Navin Mangalee': 142,\n                    'Declan Cannon': 143, 'Dana G. Whitney': 144, 'Forest Boyce': 145, 'Wayne Lordan': 146,\n                    'Jose R. Betancourt': 147, 'Jamie P. Spencer': 148, 'Jeffrey Sanchez': 149, 'Adrian Flores': 150,\n                    'Rosario Montanez': 151, 'Jorge L. Vargas Jr.': 152, 'Antonio A. Gallardo': 153,\n                    'Shannon Uske': 154, 'Nathan Vickers': 155, 'Jose Antonio Gallego': 156,\n                    'Brian Joseph Hernandez Jr.': 157, 'Angel Cruz': 158, 'Daisuke Fukumoto': 159, 'Miyabi Muto': 160,\n                    'Angel Suarez': 161, 'Virginia Tormey': 162, 'Luca Panici': 163, 'Graham Watters': 164,\n                    'Edgar S. Prado': 165, 'Darren Nagle': 166, 'Christophe Soumillon': 167, 'Michael Hussey': 168,\n                    'Rachael Blackmore': 169, 'Suguru Hamanaka': 170, 'Thomas Garner': 171, 'Ben Curtis': 172,\n                    'Jozef Bojko': 173, 'Andrea Atzeni': 174, 'Stephane Pasquier': 175, 'Sam Twiston-Davies': 176,\n                    'Tony Piccone': 177}\nNUMBER_TO_JOCKEY = {0: 'Andre Shivnarine Worrie', 1: 'Manuel Franco', 2: 'Dylan Davis', 3: 'Irad Ortiz Jr.',\n                    4: 'Samuel Jimenez', 5: 'Heman K. Harkie', 6: 'Joey R. Martinez', 7: 'Rajiv Maragh',\n                    8: 'Reylu Gutierrez', 9: 'Jose L. Ortiz', 10: 'Silvestre Gonzalez', 11: 'Junior Alvarado',\n                    12: 'Gerard Galligan', 13: 'Jack Doyle', 14: 'Victor R. Carrasco', 15: 'Benjamin Hernandez',\n                    16: 'Hector Rafael Diaz Jr.', 17: 'Eric Cancel', 18: 'Oscar Gomez', 19: 'Jorge A. Vargas Jr.',\n                    20: 'Joel Rosario', 21: 'Carlos J. Hernandez', 22: 'Michael J. Luzzi',\n                    23: 'Rafael Manuel Hernandez', 24: 'Luis R. Reyes', 25: 'Jose A. Bracho', 26: 'Jose Lezcano',\n                    27: 'Luis A. Rodriguez Castro', 28: 'Samuel Camacho Jr.', 29: 'Danny Mullins',\n                    30: 'Kendrick Carmouche', 31: 'Ruben Silvera', 32: 'Emmanuel Esquivel', 33: 'Dalton Brown',\n                    34: 'Ricardo Santana Jr.', 35: 'Sean McDermott', 36: 'Michael Mitchell', 37: 'Julio Correa',\n                    38: 'Keivan Serrano', 39: 'Harry Hernandez', 40: 'Luis Saez', 41: 'Joe Bravo',\n                    42: 'John R. Velazquez', 43: 'Ross Geraghty', 44: 'David Cohen', 45: 'Javier Castellano',\n                    46: 'Tyler Gaffalione', 47: 'Jevian Toledo', 48: 'Wilmer A. Garcia', 49: 'Jose Baez',\n                    50: 'Chris Landeros', 51: 'Winston R. Kay', 52: 'Joel Sone', 53: 'Paco Lopez', 54: 'Gary Richards',\n                    55: 'Kirk Johnson', 56: 'Julien R. Leparoux', 57: 'Channing Hill', 58: 'Jorge M. Perez',\n                    59: 'Nik Juarez', 60: 'Sheldon Russell', 61: 'Kevin Carmona', 62: 'Vince Halliday',\n                    63: 'John Bisono', 64: 'Emisael Jaramillo', 65: 'J. D. Acosta', 66: 'Mike E. Smith',\n                    67: 'Erick Lopez', 68: 'Carol Cedeno', 69: 'Christopher P. DeCarlo', 70: 'Corey J. Lanerie',\n                    71: 'Declan Carroll', 72: 'Jorge Ruiz', 73: 'William McCarthy', 74: 'Miguel A. Melendez',\n                    75: 'Talbert Howell', 76: 'Nazario Alvarado', 77: 'Christian Santiago Reyes', 78: 'Edward Escobar',\n                    79: 'Flavien Prat', 80: 'Kevin Gomez', 81: 'Jose F. Rojas', 82: 'Katie Davis',\n                    83: 'Julian Pimentel', 84: 'Pablo Fragoso', 85: 'Jeremias Flores', 86: 'Feargal Lynch',\n                    87: 'Bernard Dalton', 88: 'Jose C. Ferrer', 89: 'Kieran Norris', 90: 'Dyn Panell',\n                    91: 'Leonardo Corujo', 92: 'Edwin Rivera', 93: 'Tzeonn Chang', 94: 'Jaime Rodriguez',\n                    95: 'Georgina Sergeon', 96: 'Jomar Torres', 97: 'Trevor McCarthy', 98: 'Tyler Conner',\n                    99: 'Richard A. Bracho', 100: 'Adam Beschizza', 101: 'Steven Ronald Bahen', 102: 'Barry Foley',\n                    103: 'Cristina Bonilla', 104: 'Mario Gutierrez', 105: 'Johan Rosado', 106: 'Charles C. Lopez',\n                    107: 'Jomar Garcia', 108: 'Frankie Pennington', 109: 'Angel R. Rodriguez', 110: 'Florent Geroux',\n                    111: 'Robbie G. Davis', 112: 'Mark Watts', 113: 'Tyler Baze', 114: 'Kody Kellenberger',\n                    115: 'Tammi Piermarini', 116: 'Anthony Salgado', 117: 'Weston Hamilton', 118: 'Alex Cintron',\n                    119: 'Joseph Talamo', 120: 'Jose Angel Garcia', 121: 'Grant Whitacre', 122: 'Luis Cardenas',\n                    123: 'Gavin Coetzee', 124: 'Mychel J. Sanchez', 125: 'Tomas B. Mejia', 126: 'Daniel Centeno',\n                    127: 'Jeremy Rose', 128: 'Andrea C. Rodriguez', 129: 'Charlie Amaro', 130: 'Emanuel De Diego',\n                    131: 'Abner Adorno', 132: 'Arienne Cox', 133: 'Sophie Doyle', 134: 'Shaun Bridgmohan',\n                    135: 'Andrew Wolfsont', 136: 'Leonel Reyes', 137: 'Cory Orm', 138: 'Victor Espinoza',\n                    139: 'Angel Castillo', 140: 'Adam Bowman', 141: 'Martin Chuan', 142: 'Navin Mangalee',\n                    143: 'Declan Cannon', 144: 'Dana G. Whitney', 145: 'Forest Boyce', 146: 'Wayne Lordan',\n                    147: 'Jose R. Betancourt', 148: 'Jamie P. Spencer', 149: 'Jeffrey Sanchez', 150: 'Adrian Flores',\n                    151: 'Rosario Montanez', 152: 'Jorge L. Vargas Jr.', 153: 'Antonio A. Gallardo',\n                    154: 'Shannon Uske', 155: 'Nathan Vickers', 156: 'Jose Antonio Gallego',\n                    157: 'Brian Joseph Hernandez Jr.', 158: 'Angel Cruz', 159: 'Daisuke Fukumoto', 160: 'Miyabi Muto',\n                    161: 'Angel Suarez', 162: 'Virginia Tormey', 163: 'Luca Panici', 164: 'Graham Watters',\n                    165: 'Edgar S. Prado', 166: 'Darren Nagle', 167: 'Christophe Soumillon', 168: 'Michael Hussey',\n                    169: 'Rachael Blackmore', 170: 'Suguru Hamanaka', 171: 'Thomas Garner', 172: 'Ben Curtis',\n                    173: 'Jozef Bojko', 174: 'Andrea Atzeni', 175: 'Stephane Pasquier', 176: 'Sam Twiston-Davies',\n                    177: 'Tony Piccone'}","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**To be continued**\n\n\nIn order to make predicitons, we decided to take the following two approaches:\n\ni) a brut force approach with a deep neuronal network\n\nii) an approach with a bit of philosophy behind, where each node is represented by a horse and has as node-parameters the characteristics of the respective horse\n\n**You can catch up with our approaches following the link:**\nhttps://drive.google.com/drive/u/0/folders/1Jvf2KWCz8AZwxEXHbocw_cqVi9Xeebva\n","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}}]}