{"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"sourceId":82253,"databundleVersionId":8965849,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"colab":{"provenance":[],"gpuType":"T4"},"accelerator":"GPU"},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# # Input data files are available in the read-only \"../input/\" directory\n# # For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\"\n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","id":"WfioHTyUhb-8","outputId":"ec72ed83-82fb-4beb-a309-c424f0be9804","execution":{"iopub.status.busy":"2024-06-29T01:48:59.600699Z","iopub.execute_input":"2024-06-29T01:48:59.601119Z","iopub.status.idle":"2024-06-29T01:49:01.006499Z","shell.execute_reply.started":"2024-06-29T01:48:59.601085Z","shell.execute_reply":"2024-06-29T01:49:01.005227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from google.colab import drive\n# drive.mount('/content/drive')","metadata":{"id":"IrKmqfXJhhb2","outputId":"ed9fde4a-8009-4040-cd1f-563e1462ae30","execution":{"iopub.status.busy":"2024-06-29T01:49:01.008587Z","iopub.execute_input":"2024-06-29T01:49:01.009113Z","iopub.status.idle":"2024-06-29T01:49:01.013763Z","shell.execute_reply.started":"2024-06-29T01:49:01.009081Z","shell.execute_reply":"2024-06-29T01:49:01.012285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# Load the datasets\ntrain_data = pd.read_csv(r\"/kaggle/input/f1nalyze-datathon-ieeecsmuj/train.csv\")\ntest_data = pd.read_csv(r\"/kaggle/input/f1nalyze-datathon-ieeecsmuj/test.csv\")\n","metadata":{"id":"Qt4f5U5ahb_I","outputId":"a85adb1a-92af-49f9-cb85-9477d1b7ad74","execution":{"iopub.status.busy":"2024-06-29T01:50:09.024052Z","iopub.execute_input":"2024-06-29T01:50:09.025229Z","iopub.status.idle":"2024-06-29T01:50:55.328805Z","shell.execute_reply.started":"2024-06-29T01:50:09.025185Z","shell.execute_reply":"2024-06-29T01:50:55.327500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"id":"ewcXkCdThb_K","outputId":"f1496991-fc97-4487-eb2e-89dab23738e6","execution":{"iopub.status.busy":"2024-06-29T01:51:37.585833Z","iopub.execute_input":"2024-06-29T01:51:37.587113Z","iopub.status.idle":"2024-06-29T01:51:37.633709Z","shell.execute_reply.started":"2024-06-29T01:51:37.587068Z","shell.execute_reply":"2024-06-29T01:51:37.632526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.columns","metadata":{"id":"Y-jAas8nhb_L","outputId":"c8186877-1dee-4a3b-fffc-226b75a9360e","execution":{"iopub.status.busy":"2024-06-29T01:51:38.070917Z","iopub.execute_input":"2024-06-29T01:51:38.071326Z","iopub.status.idle":"2024-06-29T01:51:38.080177Z","shell.execute_reply.started":"2024-06-29T01:51:38.071296Z","shell.execute_reply":"2024-06-29T01:51:38.078922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Up on Observing the Data From Excel sheet visually. It is founded that the null values are not straight forward and given as `\\N` instead of NAN values**","metadata":{"id":"uIFbETDchb_M"}},{"cell_type":"code","source":"# Replace '\\N' with NaN\nimport numpy as np\ntrain_data.replace(r'\\\\N', np.nan, regex=True, inplace=True)\ntest_data.replace(r'\\\\N', np.nan, regex=True, inplace=True)","metadata":{"id":"RH931e-8hb_Q","execution":{"iopub.status.busy":"2024-06-29T01:51:38.152254Z","iopub.execute_input":"2024-06-29T01:51:38.152704Z","iopub.status.idle":"2024-06-29T01:53:13.347557Z","shell.execute_reply.started":"2024-06-29T01:51:38.152645Z","shell.execute_reply":"2024-06-29T01:53:13.346325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"RyOfE0lVhb_S","outputId":"b62cbdd9-27d3-48c5-e20d-10fa11794f37","execution":{"iopub.status.busy":"2024-06-29T01:53:13.349820Z","iopub.execute_input":"2024-06-29T01:53:13.350212Z","iopub.status.idle":"2024-06-29T01:53:13.376537Z","shell.execute_reply.started":"2024-06-29T01:53:13.350180Z","shell.execute_reply":"2024-06-29T01:53:13.375390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.isnull().sum()","metadata":{"id":"wkbhoo1Lhb_T","outputId":"e065ae8d-ce1a-4247-cb5a-b2215e79365d","execution":{"iopub.status.busy":"2024-06-29T01:53:13.377986Z","iopub.execute_input":"2024-06-29T01:53:13.378335Z","iopub.status.idle":"2024-06-29T01:53:14.453571Z","shell.execute_reply.started":"2024-06-29T01:53:13.378285Z","shell.execute_reply":"2024-06-29T01:53:14.452392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**From the initial Observation, There seems to be lot of missing data which we should look for Cleaning:**\n### Lets try to figure out different steps to handle these missing values.\n\n**Columns with Full Missing Values:**\n\nColumns like `fp1_date, fp1_time, fp2_date, fp2_time, fp3_date, fp3_time, quali_date, quali_time, sprint_date, sprint_time` are entirely missing. These columns can be dropped since they don't provide any information.\n\n**Columns with Significant Missing Values:**\n\nColumns like position_x, time_x, timetaken_in_millisec, fastestLap, rank, fastestLapTime, max_speed, time_y have significant missing values. We need to decide how to handle these:\n\n**For position_x:** As it's highly missing and might be critical, investigate if imputing is possible.\n**For time_x, timetaken_in_millisec:** These can be dropped or filled with a default value if necessary.\n**For fastestLap, rank, fastestLapTime, max_speed:** These can be filled with the mean or median or dropped if not critical.\n**For time_y:** have to Check if this is critical; if not, it can be dropped.\ntime_y is time of the race which will not contribute to the racers position so it can be dropped","metadata":{"id":"Vd1GvhRShb_U"}},{"cell_type":"code","source":"# Drop columns with all missing values\ncolumns_to_drop = [\n    'fp1_date', 'fp1_time', 'fp2_date', 'fp2_time', 'fp3_date', 'fp3_time',\n    'quali_date', 'quali_time', 'sprint_date', 'sprint_time'\n]\ntrain_data.drop(columns=columns_to_drop, inplace=True)\ntest_data.drop(columns=columns_to_drop, inplace=True)","metadata":{"id":"zZ2rYYAlhb_V","execution":{"iopub.status.busy":"2024-06-29T01:53:14.456404Z","iopub.execute_input":"2024-06-29T01:53:14.456778Z","iopub.status.idle":"2024-06-29T01:53:15.790531Z","shell.execute_reply.started":"2024-06-29T01:53:14.456748Z","shell.execute_reply":"2024-06-29T01:53:15.789386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Imputation Technique:\n\nWill use median imputation as there is a high possibility of outliers in this large dataset inorder to avoid .","metadata":{"id":"Qx8-87T5hb_W"}},{"cell_type":"code","source":"def convert_time_to_millisec(time_str):\n    if pd.isna(time_str):\n        return np.nan\n    if ':' in time_str:\n        parts = time_str.split(':')\n        return int(parts[0]) * 60000 + float(parts[1]) * 1000\n    return float(time_str) * 1000","metadata":{"id":"6rbUO6dbhb_W","execution":{"iopub.status.busy":"2024-06-29T01:53:15.792008Z","iopub.execute_input":"2024-06-29T01:53:15.792364Z","iopub.status.idle":"2024-06-29T01:53:15.798789Z","shell.execute_reply.started":"2024-06-29T01:53:15.792334Z","shell.execute_reply":"2024-06-29T01:53:15.797543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['time_x'] = train_data['time_x'].apply(convert_time_to_millisec)\ntrain_data['fastestLapTime'] = train_data['fastestLapTime'].apply(convert_time_to_millisec)\n\ntest_data['time_x'] = test_data['time_x'].apply(convert_time_to_millisec)\ntest_data['fastestLapTime'] = test_data['fastestLapTime'].apply(convert_time_to_millisec)\n","metadata":{"id":"N06mcqnYhb_X","execution":{"iopub.status.busy":"2024-06-29T01:53:15.800558Z","iopub.execute_input":"2024-06-29T01:53:15.801087Z","iopub.status.idle":"2024-06-29T01:53:24.657993Z","shell.execute_reply.started":"2024-06-29T01:53:15.801042Z","shell.execute_reply":"2024-06-29T01:53:24.656738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Handling significant missing values\ncolumns_to_fill_median = [\n    'time_x', 'timetaken_in_millisec', 'fastestLap', 'rank',\n    'fastestLapTime', 'max_speed'\n]\n\nfor column in columns_to_fill_median:\n    train_data[column] = train_data[column].astype(float)\n    train_data[column].fillna(train_data[column].median(), inplace=True)\n    test_data[column] = test_data[column].astype(float)\n    test_data[column].fillna(test_data[column].median(), inplace=True)","metadata":{"id":"-nEomg30hb_f","execution":{"iopub.status.busy":"2024-06-29T01:53:24.659227Z","iopub.execute_input":"2024-06-29T01:53:24.659555Z","iopub.status.idle":"2024-06-29T01:53:26.124026Z","shell.execute_reply.started":"2024-06-29T01:53:24.659528Z","shell.execute_reply":"2024-06-29T01:53:26.122766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.drop(columns=['time_y'], inplace=True)\ntest_data.drop(columns=['time_y'], inplace=True)","metadata":{"id":"f6b0bYxUhb_h","execution":{"iopub.status.busy":"2024-06-29T01:53:26.125334Z","iopub.execute_input":"2024-06-29T01:53:26.125653Z","iopub.status.idle":"2024-06-29T01:53:27.487623Z","shell.execute_reply.started":"2024-06-29T01:53:26.125627Z","shell.execute_reply":"2024-06-29T01:53:27.486459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['position_x'].value_counts()","metadata":{"id":"3tuxy61Dhb_i","outputId":"fa7007cc-662d-4be1-bf6e-1f521857a598","execution":{"iopub.status.busy":"2024-06-29T01:53:27.489001Z","iopub.execute_input":"2024-06-29T01:53:27.489349Z","iopub.status.idle":"2024-06-29T01:53:27.802382Z","shell.execute_reply.started":"2024-06-29T01:53:27.489320Z","shell.execute_reply":"2024-06-29T01:53:27.800968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['positionText_x'].value_counts()","metadata":{"id":"M2D1UEY-hb_i","outputId":"ce37da0d-0f5f-4469-d6e1-3e53c20acdb4","execution":{"iopub.status.busy":"2024-06-29T01:53:27.805640Z","iopub.execute_input":"2024-06-29T01:53:27.806154Z","iopub.status.idle":"2024-06-29T01:53:28.220859Z","shell.execute_reply.started":"2024-06-29T01:53:27.806083Z","shell.execute_reply":"2024-06-29T01:53:28.219619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" The positionText_x column contains not only numerical finishing positions but also several non-numeric values (e.g., R, F, W, D, N, E):\n\n* R: Retired\n* F: Finished (but did not complete the race)\n* W: Withdrew\n* D: Disqualified\n* N: Not classified\n* E: Excluded","metadata":{"id":"lzMYHay7hb_j"}},{"cell_type":"code","source":"# Extract non-numeric statuses to a new column 'statusText_x'\nnon_numeric_statuses = ['R', 'F', 'W', 'D', 'N', 'E']\ntrain_data['statusText_x'] = train_data['positionText_x'].apply(lambda x: x if x in non_numeric_statuses else np.nan)\ntest_data['statusText_x'] = test_data['positionText_x'].apply(lambda x: x if x in non_numeric_statuses else np.nan)\n\n# Replace non-numeric values in 'positionText_x' with NaN and convert to numeric\ntrain_data['positionText_x'] = pd.to_numeric(train_data['positionText_x'], errors='coerce')\ntest_data['positionText_x'] = pd.to_numeric(test_data['positionText_x'], errors='coerce')","metadata":{"id":"Ip7Oa9Tdhb_j","execution":{"iopub.status.busy":"2024-06-29T01:53:28.222574Z","iopub.execute_input":"2024-06-29T01:53:28.223072Z","iopub.status.idle":"2024-06-29T01:53:33.069816Z","shell.execute_reply.started":"2024-06-29T01:53:28.223031Z","shell.execute_reply":"2024-06-29T01:53:33.068303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### postionText_x and position_x indicates same values but in a different formats so having one column would be sufficient.","metadata":{"id":"NUO-Ai0Ahb_k"}},{"cell_type":"code","source":"train_data.dropna(subset=['position_x'], inplace=True)\ntest_data.dropna(subset=['position_x'], inplace=True)\ntrain_data['position_x'].isnull().sum()","metadata":{"id":"QNq7SX4Uhb_k","outputId":"e56290b9-4bb0-4003-f549-5a6331b1b91f","execution":{"iopub.status.busy":"2024-06-29T01:53:33.071497Z","iopub.execute_input":"2024-06-29T01:53:33.071990Z","iopub.status.idle":"2024-06-29T01:53:34.519039Z","shell.execute_reply.started":"2024-06-29T01:53:33.071946Z","shell.execute_reply":"2024-06-29T01:53:34.517726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['positionText_x'].isnull().sum()","metadata":{"id":"L-TwTOgbhb_k","outputId":"7ee10db3-5e1d-45b6-e3d0-33541d5cb2b4","execution":{"iopub.status.busy":"2024-06-29T01:53:34.520626Z","iopub.execute_input":"2024-06-29T01:53:34.521108Z","iopub.status.idle":"2024-06-29T01:53:34.531394Z","shell.execute_reply.started":"2024-06-29T01:53:34.521067Z","shell.execute_reply":"2024-06-29T01:53:34.530205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_data.drop(columns=['position_x'], inplace=True)\n# test_data.drop(columns=['position_x'], inplace=True)","metadata":{"id":"WU1vSewjhb_l","execution":{"iopub.status.busy":"2024-06-29T01:54:00.309429Z","iopub.execute_input":"2024-06-29T01:54:00.310003Z","iopub.status.idle":"2024-06-29T01:54:00.322061Z","shell.execute_reply.started":"2024-06-29T01:54:00.309963Z","shell.execute_reply":"2024-06-29T01:54:00.320390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['positionText_x'] = train_data['positionText_x'].astype(int)\ntest_data['positionText_x'] = test_data['positionText_x'].astype(int)","metadata":{"id":"-1AgTmHOhb_l","execution":{"iopub.status.busy":"2024-06-29T01:54:17.314398Z","iopub.execute_input":"2024-06-29T01:54:17.314859Z","iopub.status.idle":"2024-06-29T01:54:17.327653Z","shell.execute_reply.started":"2024-06-29T01:54:17.314826Z","shell.execute_reply":"2024-06-29T01:54:17.326476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"aEb0TAwLhb_m","outputId":"c52eb210-3305-4039-aec2-87cd2e3cced6","execution":{"iopub.status.busy":"2024-06-29T01:54:18.504336Z","iopub.execute_input":"2024-06-29T01:54:18.504813Z","iopub.status.idle":"2024-06-29T01:54:18.520045Z","shell.execute_reply.started":"2024-06-29T01:54:18.504776Z","shell.execute_reply":"2024-06-29T01:54:18.518487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"id":"_Yy2DKvqhb_m","outputId":"b3f5a250-e664-4f3e-b4ff-305e8e0e3657","execution":{"iopub.status.busy":"2024-06-29T01:54:19.370178Z","iopub.execute_input":"2024-06-29T01:54:19.370610Z","iopub.status.idle":"2024-06-29T01:54:22.770176Z","shell.execute_reply.started":"2024-06-29T01:54:19.370577Z","shell.execute_reply":"2024-06-29T01:54:22.768766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Data Arrangement after initial analysis\n\n### Relevant Features for Predicting Finishing Position\nRace and Driver Identifiers:\n\n**resultId, racerId, driverId, constructorId, raceId_y**\nThese identifiers are useful for merging datasets and tracking specific entities but do not directly contribute to prediction.\n\n### Race-specific Features:\n\n* grid: Starting position on the grid.\n* points: Points scored in the race.\n* laps: Number of laps completed.\n* time_x, timetaken_in_millisec: Total time taken to complete the race.\n* fastestLap, fastestLapTime: Information on the fastest lap.\n* rank: Rank in the race.\n* max_speed: Maximum speed achieved during the race.\n* statusId, statusText_x: Status of the race or driver.\n\n### Driver and Constructor Details:\n\n* forename, surname: Driver's name (not directly useful but can be encoded if needed).\n* dob: Driver's date of birth (can be transformed to age).\n* nationality: Driver's nationality.\n* driverStandingsId, points_y, position, positionText_y, wins: Driver's standings and performance metrics.\n* constructorRef, company, nationality_y: Constructor details.\n\n### Race Metadata:\n\n* year, round, circuitId, grand_prix: Information about the race event.\n* date: Date of the race.\n* url_x, url_y, url: URLs for additional information (not useful for prediction).","metadata":{"id":"S49FPR6lhb_n"}},{"cell_type":"markdown","source":"## Features Less Likely to Contribute to Prediction\n\n* **resultId, racerId, driverId, constructorId, raceId_y**: Primarily identifiers, useful for merging but not for prediction.\n* **url_x, url_y, url**: Links to external resources, not useful for prediction.\n* **driverRef, driver_num, driver_code**: Redundant with driverId and less useful for prediction.\n* **forename, surname**: Names of drivers, which are not useful for prediction.\n* **company**: Constructor's company, which might be redundant with constructorRef.","metadata":{"id":"-9OACTRbhb_n"}},{"cell_type":"code","source":"# List of columns to drop\nnew_columns_to_drop = [\n    'resultId', 'racerId', 'driverId', 'constructorId', 'raceId_y',\n    'url_x', 'url_y', 'url', 'driver_num', 'driver_code',\n    'forename', 'surname', 'statusText_x'\n]\n\n# Drop the columns from the training and test datasets\ntrain_data.drop(columns=new_columns_to_drop, inplace=True)\ntest_data.drop(columns=new_columns_to_drop, inplace=True)\n\n","metadata":{"id":"IegAvptkhb_n","execution":{"iopub.status.busy":"2024-06-29T01:57:58.803171Z","iopub.execute_input":"2024-06-29T01:57:58.803601Z","iopub.status.idle":"2024-06-29T01:57:59.351045Z","shell.execute_reply.started":"2024-06-29T01:57:58.803567Z","shell.execute_reply":"2024-06-29T01:57:59.349465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"1psLdppHhb_o","outputId":"1343541b-d627-4db0-9b97-d9d97037d9b0","execution":{"iopub.status.busy":"2024-06-29T01:58:42.017298Z","iopub.execute_input":"2024-06-29T01:58:42.017857Z","iopub.status.idle":"2024-06-29T01:58:42.034821Z","shell.execute_reply.started":"2024-06-29T01:58:42.017817Z","shell.execute_reply":"2024-06-29T01:58:42.033018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['dob']","metadata":{"id":"bIsPuuy2hb_o","outputId":"d0865762-bea2-4178-d018-1a024fa5e54a","execution":{"iopub.status.busy":"2024-06-29T01:58:43.000279Z","iopub.execute_input":"2024-06-29T01:58:43.000729Z","iopub.status.idle":"2024-06-29T01:58:43.011475Z","shell.execute_reply.started":"2024-06-29T01:58:43.000687Z","shell.execute_reply":"2024-06-29T01:58:43.009949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert 'dob' to datetime\ntrain_data['dob'] = pd.to_datetime(train_data['dob'], errors='coerce')\ntest_data['dob'] = pd.to_datetime(test_data['dob'], errors='coerce')\n","metadata":{"id":"zlI4HQQWhb_p","outputId":"56adb63d-cc8e-40b7-ba18-8d9e06d9d819","execution":{"iopub.status.busy":"2024-06-29T01:58:44.558292Z","iopub.execute_input":"2024-06-29T01:58:44.558722Z","iopub.status.idle":"2024-06-29T01:58:45.028579Z","shell.execute_reply.started":"2024-06-29T01:58:44.558662Z","shell.execute_reply":"2024-06-29T01:58:45.027222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Calculate driver's age at the time of the race\ntrain_data['age'] = train_data.apply(lambda row: row['year'] - row['dob'].year if pd.notnull(row['dob']) else np.nan, axis=1)\ntest_data['age'] = test_data.apply(lambda row: row['year'] - row['dob'].year if pd.notnull(row['dob']) else np.nan, axis=1)\n","metadata":{"id":"YCcs4CJYhb_q","execution":{"iopub.status.busy":"2024-06-29T01:58:48.990313Z","iopub.execute_input":"2024-06-29T01:58:48.990921Z","iopub.status.idle":"2024-06-29T01:59:45.711268Z","shell.execute_reply.started":"2024-06-29T01:58:48.990873Z","shell.execute_reply":"2024-06-29T01:59:45.709958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data[['dob', 'age']].head()","metadata":{"id":"ez5-AuMMhb_q","outputId":"37a78ffb-daa7-4dd8-df58-241b63dba5c1","execution":{"iopub.status.busy":"2024-06-29T01:59:45.713618Z","iopub.execute_input":"2024-06-29T01:59:45.714084Z","iopub.status.idle":"2024-06-29T01:59:45.734790Z","shell.execute_reply.started":"2024-06-29T01:59:45.714043Z","shell.execute_reply":"2024-06-29T01:59:45.733695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"UV3zprxuhb_r","outputId":"8ddd0351-2e33-4948-a46e-9b3c3a629caf","execution":{"iopub.status.busy":"2024-06-29T01:59:45.736186Z","iopub.execute_input":"2024-06-29T01:59:45.736509Z","iopub.status.idle":"2024-06-29T01:59:45.750401Z","shell.execute_reply.started":"2024-06-29T01:59:45.736482Z","shell.execute_reply":"2024-06-29T01:59:45.749201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Drop 'dob' column after extracting age\ntrain_data.drop(columns=['dob'], inplace=True)\ntest_data.drop(columns=['dob'], inplace=True)\n\n# Encode categorical features\n# categorical_features = ['nationality', 'constructorRef', 'grand_prix', 'statusText_x']\n# train_data = pd.get_dummies(train_data, columns=categorical_features)\n# test_data = pd.get_dummies(test_data, columns=categorical_features)","metadata":{"id":"Bm7y6GEFhb_r","execution":{"iopub.status.busy":"2024-06-29T01:59:45.753469Z","iopub.execute_input":"2024-06-29T01:59:45.753922Z","iopub.status.idle":"2024-06-29T01:59:46.197632Z","shell.execute_reply.started":"2024-06-29T01:59:45.753869Z","shell.execute_reply":"2024-06-29T01:59:46.196219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n[col for col in train_data.select_dtypes(include=['object']).columns]\n","metadata":{"id":"eyrw9QKMhb_s","outputId":"368ecd51-d280-4258-9642-00e057f43519","execution":{"iopub.status.busy":"2024-06-29T01:59:46.199646Z","iopub.execute_input":"2024-06-29T01:59:46.200072Z","iopub.status.idle":"2024-06-29T01:59:47.047129Z","shell.execute_reply.started":"2024-06-29T01:59:46.200037Z","shell.execute_reply":"2024-06-29T01:59:47.045768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert 'date' to datetime\ntrain_data['date'] = pd.to_datetime(train_data['date'], errors='coerce')\ntest_data['date'] = pd.to_datetime(test_data['date'], errors='coerce')\n\n# Extract components from the datetime column\ntrain_data['race_year'] = train_data['date'].dt.year\ntrain_data['race_month'] = train_data['date'].dt.month\ntrain_data['race_day'] = train_data['date'].dt.day\n\ntest_data['race_year'] = test_data['date'].dt.year\ntest_data['race_month'] = test_data['date'].dt.month\ntest_data['race_day'] = test_data['date'].dt.day","metadata":{"id":"PfQwkfgahb_s","outputId":"217dee7a-5395-4dc3-d172-442b7b7d8576","execution":{"iopub.status.busy":"2024-06-29T01:59:47.048586Z","iopub.execute_input":"2024-06-29T01:59:47.049069Z","iopub.status.idle":"2024-06-29T01:59:47.582911Z","shell.execute_reply.started":"2024-06-29T01:59:47.049023Z","shell.execute_reply":"2024-06-29T01:59:47.581408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Drop the original datetime column\ntrain_data.drop(columns=['date'], inplace=True)\ntest_data.drop(columns=['date'], inplace=True)\n# train_data.drop(columns=['statusText_x'], inplace=True)\n# test_data.drop(columns=['statusText_x'], inplace=True)","metadata":{"id":"lFQJXU9xhb_t","execution":{"iopub.status.busy":"2024-06-29T01:59:47.584583Z","iopub.execute_input":"2024-06-29T01:59:47.585011Z","iopub.status.idle":"2024-06-29T01:59:48.052739Z","shell.execute_reply.started":"2024-06-29T01:59:47.584976Z","shell.execute_reply":"2024-06-29T01:59:48.051592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extended Label Encoding Technique\nfrom sklearn.preprocessing import LabelEncoder\nclass ExtendedLabelEncoder(LabelEncoder):\n    def __init__(self):\n        super().__init__()\n        self.classes_ = np.array([])\n\n    def fit(self, y):\n        self.classes_ = np.unique(y)\n        return self\n\n    def transform(self, y):\n        unseen = set(y) - set(self.classes_)\n        if unseen:\n            self.classes_ = np.append(self.classes_, list(unseen))\n        return super().transform(y)\n\n    def fit_transform(self, y):\n        self.fit(y)\n        return self.transform(y)","metadata":{"id":"Z1HbRFJPhb_3","execution":{"iopub.status.busy":"2024-06-29T02:00:13.170176Z","iopub.execute_input":"2024-06-29T02:00:13.170628Z","iopub.status.idle":"2024-06-29T02:00:13.265427Z","shell.execute_reply.started":"2024-06-29T02:00:13.170596Z","shell.execute_reply":"2024-06-29T02:00:13.263941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['positionText_y'].unique()","metadata":{"id":"Hm6hhZT_hb_4","outputId":"0c5c0052-f5bf-4ffa-a369-a7b2ccd761c6","execution":{"iopub.status.busy":"2024-06-29T02:00:14.909162Z","iopub.execute_input":"2024-06-29T02:00:14.909636Z","iopub.status.idle":"2024-06-29T02:00:15.008474Z","shell.execute_reply.started":"2024-06-29T02:00:14.909602Z","shell.execute_reply":"2024-06-29T02:00:15.007030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.info()","metadata":{"id":"mwA2Gfuahb_4","outputId":"e25f40f6-c682-4aec-9239-243e64c7f1f2","execution":{"iopub.status.busy":"2024-06-29T02:00:15.981025Z","iopub.execute_input":"2024-06-29T02:00:15.981473Z","iopub.status.idle":"2024-06-29T02:00:16.267870Z","shell.execute_reply.started":"2024-06-29T02:00:15.981438Z","shell.execute_reply":"2024-06-29T02:00:16.266693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unnecessary_columns = ['number', 'driverStandingsId', 'raceId_y','grand_prix']\ntrain_data.drop(columns=unnecessary_columns, inplace=True, errors='ignore')\ntest_data.drop(columns=unnecessary_columns, inplace=True, errors='ignore')","metadata":{"id":"w7L-Z0aihb_5","execution":{"iopub.status.busy":"2024-06-29T02:00:17.781407Z","iopub.execute_input":"2024-06-29T02:00:17.781935Z","iopub.status.idle":"2024-06-29T02:00:18.160397Z","shell.execute_reply.started":"2024-06-29T02:00:17.781896Z","shell.execute_reply":"2024-06-29T02:00:18.159098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.drop(columns=\"positionText_y\", inplace=True, errors='ignore')","metadata":{"id":"da9oRX_4hb_6","execution":{"iopub.status.busy":"2024-06-29T02:00:31.717146Z","iopub.execute_input":"2024-06-29T02:00:31.718191Z","iopub.status.idle":"2024-06-29T02:00:32.028156Z","shell.execute_reply.started":"2024-06-29T02:00:31.718151Z","shell.execute_reply":"2024-06-29T02:00:32.026910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert remaining object columns to numeric using LabelEncoder\nlabel_encoders = {}\nfor col in ['nationality', 'constructorRef', 'nationality_y', 'status','position_x','company','driverRef']:\n    le = ExtendedLabelEncoder()\n    train_data[col] = le.fit_transform(train_data[col].astype(str))\n    test_data[col] = le.transform(test_data[col].astype(str))\n    label_encoders[col] = le","metadata":{"id":"4DVFMOavhb_6","execution":{"iopub.status.busy":"2024-06-29T02:00:34.060541Z","iopub.execute_input":"2024-06-29T02:00:34.061437Z","iopub.status.idle":"2024-06-29T02:00:59.992474Z","shell.execute_reply.started":"2024-06-29T02:00:34.061395Z","shell.execute_reply":"2024-06-29T02:00:59.991267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"id":"-PK1yq_9hb_7","outputId":"c88063e7-47dd-44a2-9b05-3a1616041d9a","execution":{"iopub.status.busy":"2024-06-29T02:06:57.934425Z","iopub.execute_input":"2024-06-29T02:06:57.934978Z","iopub.status.idle":"2024-06-29T02:06:57.952276Z","shell.execute_reply.started":"2024-06-29T02:06:57.934939Z","shell.execute_reply":"2024-06-29T02:06:57.950885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.info()","metadata":{"id":"9fziju4Whb_7","outputId":"3593e192-bb45-43c1-9fda-1e08b1332548","execution":{"iopub.status.busy":"2024-06-29T02:06:58.095018Z","iopub.execute_input":"2024-06-29T02:06:58.095459Z","iopub.status.idle":"2024-06-29T02:06:58.123124Z","shell.execute_reply.started":"2024-06-29T02:06:58.095424Z","shell.execute_reply":"2024-06-29T02:06:58.121823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.isnull().sum().sum()","metadata":{"id":"rHRJaTGzhb_8","outputId":"530c283f-4077-4a0c-a6a5-de68ae1d9a5a","execution":{"iopub.status.busy":"2024-06-29T02:06:58.255877Z","iopub.execute_input":"2024-06-29T02:06:58.256314Z","iopub.status.idle":"2024-06-29T02:06:58.277411Z","shell.execute_reply.started":"2024-06-29T02:06:58.256282Z","shell.execute_reply":"2024-06-29T02:06:58.276056Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.isnull().sum().sum()","metadata":{"id":"IAClM0jfhb_9","outputId":"e2089122-d399-4419-934b-2df6568f3453","execution":{"iopub.status.busy":"2024-06-29T02:06:58.394549Z","iopub.execute_input":"2024-06-29T02:06:58.394950Z","iopub.status.idle":"2024-06-29T02:06:58.455389Z","shell.execute_reply.started":"2024-06-29T02:06:58.394920Z","shell.execute_reply":"2024-06-29T02:06:58.454121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"id":"sFTng0oPhb_9"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploratory Data Analysis","metadata":{"id":"ajz70O35hb_9"}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\ncorr_matrix = train_data.corr()\nplt.figure(figsize=(20, 15))\nsns.heatmap(corr_matrix, annot=True, fmt='.2f', cmap='coolwarm')\nplt.title('Feature Correlation Matrix')\nplt.show()\n\n\n","metadata":{"id":"pD0qo-3ihb_-","outputId":"a5707867-ee66-449b-8cbb-3c3c3c1b7f99","execution":{"iopub.status.busy":"2024-06-29T02:07:05.805266Z","iopub.execute_input":"2024-06-29T02:07:05.805728Z","iopub.status.idle":"2024-06-29T02:07:13.018557Z","shell.execute_reply.started":"2024-06-29T02:07:05.805686Z","shell.execute_reply":"2024-06-29T02:07:13.017373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_cols = train_data.select_dtypes(include=[np.number]).columns","metadata":{"id":"qlIfc2dBmBG4","execution":{"iopub.status.busy":"2024-06-29T01:49:04.142860Z","iopub.status.idle":"2024-06-29T01:49:04.143487Z","shell.execute_reply.started":"2024-06-29T01:49:04.143118Z","shell.execute_reply":"2024-06-29T01:49:04.143135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Distribution of the target variable\nplt.figure(figsize=(10, 5))\nsns.histplot(train_data['position'], bins=30, kde=True)\nplt.title('Distribution of Position')\nplt.show()","metadata":{"id":"f-DR2uHIhb__","outputId":"2786063d-e0f1-4322-f121-dc2d4ac1e722","execution":{"iopub.status.busy":"2024-06-29T01:49:04.144882Z","iopub.status.idle":"2024-06-29T01:49:04.145306Z","shell.execute_reply.started":"2024-06-29T01:49:04.145104Z","shell.execute_reply":"2024-06-29T01:49:04.145120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Analyze how different features affect the target variable\nfor col in numerical_cols:\n    if col != 'position':\n        plt.figure(figsize=(10, 5))\n        sns.scatterplot(data=train_data, x=col, y='position')\n        plt.title(f'Position vs {col}')\n        plt.show()\n\n","metadata":{"id":"kdewMIaRhb__","outputId":"42699251-e6eb-4dfa-ffe0-d1a1a580af50","execution":{"iopub.status.busy":"2024-06-29T01:49:04.147554Z","iopub.status.idle":"2024-06-29T01:49:04.148013Z","shell.execute_reply.started":"2024-06-29T01:49:04.147798Z","shell.execute_reply":"2024-06-29T01:49:04.147815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"id":"sLzXCQH2hcAB"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numeric_columns = train_data.select_dtypes(include=[np.number]).columns\n# Prepare the data\n\nprint(len(numeric_columns))","metadata":{"id":"YgSKyI0JhcAC","outputId":"c4389628-7718-42aa-c3e9-6dfe4a3ded3b","execution":{"iopub.status.busy":"2024-06-29T01:49:04.150313Z","iopub.status.idle":"2024-06-29T01:49:04.150825Z","shell.execute_reply.started":"2024-06-29T01:49:04.150557Z","shell.execute_reply":"2024-06-29T01:49:04.150575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numeric_test = test_data.select_dtypes(include=[np.number]).columns\nlen(numeric_test)","metadata":{"id":"_J9d4SLAhcAD","outputId":"afc2561a-6ab2-42c8-a52f-efca2202f8a0","execution":{"iopub.status.busy":"2024-06-29T01:49:04.155457Z","iopub.status.idle":"2024-06-29T01:49:04.156110Z","shell.execute_reply.started":"2024-06-29T01:49:04.155806Z","shell.execute_reply":"2024-06-29T01:49:04.155834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in numeric_columns:\n    if i not in numeric_test:\n        print(i)","metadata":{"id":"T6sRbxJ5hcAD","outputId":"daac506c-314e-4061-93f2-c88536b02091","execution":{"iopub.status.busy":"2024-06-29T01:49:04.157886Z","iopub.status.idle":"2024-06-29T01:49:04.158808Z","shell.execute_reply.started":"2024-06-29T01:49:04.158481Z","shell.execute_reply":"2024-06-29T01:49:04.158510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.metrics import mean_squared_error\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# Ensure all columns are numeric\nnumeric_columns = train_data.select_dtypes(include=[np.number]).columns\n\nnumeric_columns","metadata":{"id":"g9f-AlD1hcAE","outputId":"a34d4dd0-c9c7-420f-966b-ecf49aa9f2bc","execution":{"iopub.status.busy":"2024-06-29T01:49:04.160830Z","iopub.status.idle":"2024-06-29T01:49:04.161343Z","shell.execute_reply.started":"2024-06-29T01:49:04.161053Z","shell.execute_reply":"2024-06-29T01:49:04.161073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Prepare the data\nX = train_data[numeric_columns].drop(columns=['position'],axis=1)\n# X_test = test_data[numeric_columns]\ny = train_data['position']","metadata":{"id":"K23PF35GhcAF","execution":{"iopub.status.busy":"2024-06-29T01:49:04.163021Z","iopub.status.idle":"2024-06-29T01:49:04.163662Z","shell.execute_reply.started":"2024-06-29T01:49:04.163351Z","shell.execute_reply":"2024-06-29T01:49:04.163375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nrf = RandomForestRegressor( random_state=42)\nrf.fit(X, y)","metadata":{"id":"Wk1JTPJNhcAF","execution":{"iopub.status.busy":"2024-06-29T01:49:04.165641Z","iopub.status.idle":"2024-06-29T01:49:04.166206Z","shell.execute_reply.started":"2024-06-29T01:49:04.165971Z","shell.execute_reply":"2024-06-29T01:49:04.165998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"importances = rf.feature_importances_\nfeature_names = numeric_columns.drop(['position'])\nfeature_importance_df = pd.DataFrame({'feature': feature_names, 'importance': importances}).sort_values(by='importance', ascending=False)\nprint(feature_importance_df.head(20))","metadata":{"id":"bOwPv_9mhcAG","outputId":"52809f8c-a264-444b-f64d-49d55b8c1590","execution":{"iopub.status.busy":"2024-06-29T01:49:04.168433Z","iopub.status.idle":"2024-06-29T01:49:04.169004Z","shell.execute_reply.started":"2024-06-29T01:49:04.168725Z","shell.execute_reply":"2024-06-29T01:49:04.168749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Select the top N important features (e.g., top 20)\ntop_features = feature_importance_df.head(20)['feature']\n\n# Use only the top features for the final model\nX_top = train_data[top_features]","metadata":{"id":"2Lz5rVGphcAG","execution":{"iopub.status.busy":"2024-06-29T01:49:04.170782Z","iopub.status.idle":"2024-06-29T01:49:04.171345Z","shell.execute_reply.started":"2024-06-29T01:49:04.171058Z","shell.execute_reply":"2024-06-29T01:49:04.171081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test_top = test_data[top_features]","metadata":{"id":"0lo2Mm_ShcAH","execution":{"iopub.status.busy":"2024-06-29T01:49:04.173271Z","iopub.status.idle":"2024-06-29T01:49:04.173878Z","shell.execute_reply.started":"2024-06-29T01:49:04.173561Z","shell.execute_reply":"2024-06-29T01:49:04.173584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Split the data into training and validation sets\nX_train, X_val, y_train, y_val = train_test_split(X_top, y, test_size=0.2, random_state=42)\n\n# Train the final RandomForest model\nfinal_model = RandomForestRegressor(n_estimators=100, random_state=42, n_jobs=-1)\nfinal_model.fit(X_train, y_train)","metadata":{"id":"4dTiYzTVhcAH","outputId":"27e7d57f-686c-4768-ae08-d05f007bb64f","execution":{"iopub.status.busy":"2024-06-29T01:49:04.175552Z","iopub.status.idle":"2024-06-29T01:49:04.176134Z","shell.execute_reply.started":"2024-06-29T01:49:04.175854Z","shell.execute_reply":"2024-06-29T01:49:04.175877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Predict and evaluate on validation set\ny_val_pred = final_model.predict(X_val)\nval_rmse = np.sqrt(mean_squared_error(y_val, y_val_pred))\nprint(f'Validation RMSE: {val_rmse}')\n","metadata":{"id":"p4LY_hrPhcAI","outputId":"294f0a7d-85a0-46c3-f6bc-183d0a7f40e5","execution":{"iopub.status.busy":"2024-06-29T01:49:04.181735Z","iopub.status.idle":"2024-06-29T01:49:04.182368Z","shell.execute_reply.started":"2024-06-29T01:49:04.182053Z","shell.execute_reply":"2024-06-29T01:49:04.182077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Assuming 'final_model' is your trained RandomForest model and 'X_test_top' is your prepared test set\npredictions = final_model.predict(X_test_top)\n","metadata":{"id":"b5XASJA4hcAI","execution":{"iopub.status.busy":"2024-06-29T01:49:04.184731Z","iopub.status.idle":"2024-06-29T01:49:04.185362Z","shell.execute_reply.started":"2024-06-29T01:49:04.185046Z","shell.execute_reply":"2024-06-29T01:49:04.185071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test_top.columns","metadata":{"id":"caLrM_YxhcAJ","outputId":"6f63358a-ed81-4cfc-d439-cfed39172161","execution":{"iopub.status.busy":"2024-06-29T01:49:04.187160Z","iopub.status.idle":"2024-06-29T01:49:04.187915Z","shell.execute_reply.started":"2024-06-29T01:49:04.187597Z","shell.execute_reply":"2024-06-29T01:49:04.187621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions","metadata":{"id":"e16alUaPhcAJ","outputId":"ac1d0343-1c09-4fd6-8a0e-39dbbc860ac4","execution":{"iopub.status.busy":"2024-06-29T01:49:04.189485Z","iopub.status.idle":"2024-06-29T01:49:04.190049Z","shell.execute_reply.started":"2024-06-29T01:49:04.189771Z","shell.execute_reply":"2024-06-29T01:49:04.189793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = pd.DataFrame({\n    \"position\":predictions,\n    \"result_driver_standing\":X_test_top['result_driver_standing']\n})\nsub_df","metadata":{"id":"DAQChWJchcAK","outputId":"1724e0c4-15c6-42b8-fd0d-671b8565780c","execution":{"iopub.status.busy":"2024-06-29T01:49:04.191373Z","iopub.status.idle":"2024-06-29T01:49:04.191943Z","shell.execute_reply.started":"2024-06-29T01:49:04.191642Z","shell.execute_reply":"2024-06-29T01:49:04.191665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.to_csv('/submission.csv', index=False)","metadata":{"id":"vhBg3faihcAL","execution":{"iopub.status.busy":"2024-06-29T01:49:04.193444Z","iopub.status.idle":"2024-06-29T01:49:04.193988Z","shell.execute_reply.started":"2024-06-29T01:49:04.193716Z","shell.execute_reply":"2024-06-29T01:49:04.193739Z"},"trusted":true},"execution_count":null,"outputs":[]}]}