{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":104857,"databundleVersionId":12651513,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error, r2_score\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\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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:36:34.362704Z","iopub.execute_input":"2025-06-14T14:36:34.363245Z","iopub.status.idle":"2025-06-14T14:36:34.370014Z","shell.execute_reply.started":"2025-06-14T14:36:34.363186Z","shell.execute_reply":"2025-06-14T14:36:34.368688Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/burnout-datathon-ieeecsmuj/train.csv')\ntrain_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:36:36.014585Z","iopub.execute_input":"2025-06-14T14:36:36.014923Z","iopub.status.idle":"2025-06-14T14:36:49.745398Z","shell.execute_reply.started":"2025-06-14T14:36:36.014894Z","shell.execute_reply":"2025-06-14T14:36:49.744434Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:36:51.699829Z","iopub.execute_input":"2025-06-14T14:36:51.700174Z","iopub.status.idle":"2025-06-14T14:36:51.706622Z","shell.execute_reply.started":"2025-06-14T14:36:51.700146Z","shell.execute_reply":"2025-06-14T14:36:51.705629Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:36:53.289357Z","iopub.execute_input":"2025-06-14T14:36:53.290429Z","iopub.status.idle":"2025-06-14T14:36:53.301815Z","shell.execute_reply.started":"2025-06-14T14:36:53.290386Z","shell.execute_reply":"2025-06-14T14:36:53.300592Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:36:55.859510Z","iopub.execute_input":"2025-06-14T14:36:55.859843Z","iopub.status.idle":"2025-06-14T14:36:55.866493Z","shell.execute_reply.started":"2025-06-14T14:36:55.859819Z","shell.execute_reply":"2025-06-14T14:36:55.865427Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:36:57.729498Z","iopub.execute_input":"2025-06-14T14:36:57.729831Z","iopub.status.idle":"2025-06-14T14:36:59.054237Z","shell.execute_reply.started":"2025-06-14T14:36:57.729808Z","shell.execute_reply":"2025-06-14T14:36:59.053477Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['Penalty'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:37:01.919537Z","iopub.execute_input":"2025-06-14T14:37:01.919893Z","iopub.status.idle":"2025-06-14T14:37:02.057874Z","shell.execute_reply.started":"2025-06-14T14:37:01.919862Z","shell.execute_reply":"2025-06-14T14:37:02.056864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#handling missing values in penalty column\ntrain_df['Penalty'] = train_df['Penalty'].fillna('No Penalty')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:37:03.739558Z","iopub.execute_input":"2025-06-14T14:37:03.739873Z","iopub.status.idle":"2025-06-14T14:37:03.882204Z","shell.execute_reply.started":"2025-06-14T14:37:03.739852Z","shell.execute_reply":"2025-06-14T14:37:03.881337Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['Penalty'].isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:37:09.489495Z","iopub.execute_input":"2025-06-14T14:37:09.490361Z","iopub.status.idle":"2025-06-14T14:37:09.589625Z","shell.execute_reply.started":"2025-06-14T14:37:09.490333Z","shell.execute_reply":"2025-06-14T14:37:09.588757Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"penalty_map = {\n    'No Penalty': 0,\n    'DNS': 1,\n    'DNF': 2,\n    'Ride Through': 3,\n    '+3s': 4,\n    '+5s': 5\n}\ntrain_df['Penalty_encoded'] = train_df['Penalty'].map(penalty_map)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:37:12.709606Z","iopub.execute_input":"2025-06-14T14:37:12.709949Z","iopub.status.idle":"2025-06-14T14:37:12.848484Z","shell.execute_reply.started":"2025-06-14T14:37:12.709925Z","shell.execute_reply":"2025-06-14T14:37:12.847308Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['Penalty_encoded'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:37:14.720012Z","iopub.execute_input":"2025-06-14T14:37:14.720498Z","iopub.status.idle":"2025-06-14T14:37:14.740887Z","shell.execute_reply.started":"2025-06-14T14:37:14.720464Z","shell.execute_reply":"2025-06-14T14:37:14.739883Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"leakage_check_cols = ['Avg_Speed_kmh', 'Championship_Points',\n                     'Championship_Position','position', \n                     'points', 'starts', 'finishes', 'with_points',\n       'podiums', 'wins', 'Penalty_encoded' ]\nplt.figure(figsize=(12,6))\nsns.heatmap(train_df[leakage_check_cols + ['Lap_Time_Seconds']].corr(), annot=True, cmap='coolwarm')\nplt.title(\"Potential Leakage Feature Correlation\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:37:21.410270Z","iopub.execute_input":"2025-06-14T14:37:21.411110Z","iopub.status.idle":"2025-06-14T14:37:23.055269Z","shell.execute_reply.started":"2025-06-14T14:37:21.411080Z","shell.execute_reply":"2025-06-14T14:37:23.054375Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"safely can remove the columns points, position, avg_speed_kmh","metadata":{}},{"cell_type":"code","source":"# dividing features \n\nirrelevant_cols = ['Unique ID', 'Rider_ID', 'Penalty','Session','Avg_Speed_kmh',\n                  'sequence' , 'position' , 'points', 'rider', 'team', 'bike','shortname',\n       'circuit_name', 'rider_name', 'team_name', 'bike_name', 'min_year', 'max_year']\n\nnumerical_cols = ['Circuit_Length_km' ,'Laps' , \n                  'Grid_Position',\n                  'Championship_Points', \n                  'Championship_Position','Corners_per_Lap',\n                  'Tire_Degradation_Factor_per_Lap',\n                  'Pit_Stop_Duration_Seconds', 'years_active',\n                  'Penalty_encoded'\n                 ]\n\ncategorical_cols = ['category_x', 'Tire_Compound_Front','Tire_Compound_Rear', 'Track_Condition', 'weather', 'track']\n\nweather_cols = ['Humidity_%', 'Ambient_Temperature_Celsius', 'Track_Temperature_Celsius', 'air', 'ground']\n\nperformance_cols = ['starts', 'finishes', 'with_points','podiums','wins']\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:38:24.285763Z","iopub.execute_input":"2025-06-14T14:38:24.286161Z","iopub.status.idle":"2025-06-14T14:38:24.292418Z","shell.execute_reply.started":"2025-06-14T14:38:24.286131Z","shell.execute_reply":"2025-06-14T14:38:24.291457Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['win_rate'] = train_df['wins'] / train_df['starts'].replace(0,1)\ntrain_df['podium_rate'] = train_df['podiums'] / train_df['starts'].replace(0,1)\ntrain_df['points_rate'] = train_df['with_points'] / train_df['starts'].replace(0,1)\ntrain_df['finish_rate'] = train_df['finishes'] / train_df['starts'].replace(0,1)\n\n# weather based features\ntrain_df['temp_diff'] = train_df['Track_Temperature_Celsius'] - train_df['Ambient_Temperature_Celsius']\ntrain_df['air_ground_diff'] = train_df['air'] - train_df['ground']\n\n# categorical encoding\ntrain_df = pd.get_dummies(train_df, columns=categorical_cols, drop_first=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:38:30.090066Z","iopub.execute_input":"2025-06-14T14:38:30.090526Z","iopub.status.idle":"2025-06-14T14:38:33.918650Z","shell.execute_reply.started":"2025-06-14T14:38:30.090494Z","shell.execute_reply":"2025-06-14T14:38:33.917627Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"feature_cols = numerical_cols  + weather_cols\nderived_cols = ['win_rate', 'podium_rate', 'points_rate', 'finish_rate', 'temp_diff', 'air_ground_diff']\n\n# encoded categorical cols \nencoded_cols = [col for col in train_df.columns if any(prefix in col for prefix in ['category_x_',\n                                                                                    'Tire_Compound_Front_','Tire_Compound_Rear_',\n                                                                                    'Track_Condition_', 'weather_', 'track_'])]\n# final feature list\nfeature_cols = feature_cols + derived_cols + encoded_cols","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:38:33.920159Z","iopub.execute_input":"2025-06-14T14:38:33.920526Z","iopub.status.idle":"2025-06-14T14:38:33.926453Z","shell.execute_reply.started":"2025-06-14T14:38:33.920501Z","shell.execute_reply":"2025-06-14T14:38:33.925343Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"feature_cols","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:38:35.554315Z","iopub.execute_input":"2025-06-14T14:38:35.554656Z","iopub.status.idle":"2025-06-14T14:38:35.561014Z","shell.execute_reply.started":"2025-06-14T14:38:35.554633Z","shell.execute_reply":"2025-06-14T14:38:35.560014Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = train_df[feature_cols]\ny = train_df['Lap_Time_Seconds']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:38:46.429970Z","iopub.execute_input":"2025-06-14T14:38:46.430406Z","iopub.status.idle":"2025-06-14T14:38:46.573634Z","shell.execute_reply.started":"2025-06-14T14:38:46.430376Z","shell.execute_reply":"2025-06-14T14:38:46.572876Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\nX_train_scaled = scaler.fit_transform(X)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:38:50.394749Z","iopub.execute_input":"2025-06-14T14:38:50.395063Z","iopub.status.idle":"2025-06-14T14:38:54.340923Z","shell.execute_reply.started":"2025-06-14T14:38:50.395040Z","shell.execute_reply":"2025-06-14T14:38:54.340026Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_df = pd.read_csv('/kaggle/input/burnout-datathon-ieeecsmuj/val.csv')\nval_df\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:39:50.765409Z","iopub.execute_input":"2025-06-14T14:39:50.766328Z","iopub.status.idle":"2025-06-14T14:39:52.363135Z","shell.execute_reply.started":"2025-06-14T14:39:50.766297Z","shell.execute_reply":"2025-06-14T14:39:52.362038Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_df.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:39:52.670871Z","iopub.execute_input":"2025-06-14T14:39:52.671199Z","iopub.status.idle":"2025-06-14T14:39:52.870574Z","shell.execute_reply.started":"2025-06-14T14:39:52.671172Z","shell.execute_reply":"2025-06-14T14:39:52.869709Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#handling missing values in penalty column\nval_df['Penalty'] = val_df['Penalty'].fillna('No Penalty')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:39:55.559982Z","iopub.execute_input":"2025-06-14T14:39:55.560400Z","iopub.status.idle":"2025-06-14T14:39:55.586631Z","shell.execute_reply.started":"2025-06-14T14:39:55.560369Z","shell.execute_reply":"2025-06-14T14:39:55.585474Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_df['Penalty'].isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:39:57.109857Z","iopub.execute_input":"2025-06-14T14:39:57.110471Z","iopub.status.idle":"2025-06-14T14:39:57.131375Z","shell.execute_reply.started":"2025-06-14T14:39:57.110419Z","shell.execute_reply":"2025-06-14T14:39:57.130244Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"penalty_mapping = {\n    'No Penalty': 0,\n    'DNS': 1,\n    'DNF': 2,\n    'Ride Through': 3,\n    '+3s': 4,\n    '+5s': 5\n}\nval_df['Penalty_encoded'] = val_df['Penalty'].map(penalty_mapping)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:40:00.645580Z","iopub.execute_input":"2025-06-14T14:40:00.645907Z","iopub.status.idle":"2025-06-14T14:40:00.672524Z","shell.execute_reply.started":"2025-06-14T14:40:00.645883Z","shell.execute_reply":"2025-06-14T14:40:00.671428Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_df['Penalty_encoded'].isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:40:03.454770Z","iopub.execute_input":"2025-06-14T14:40:03.455110Z","iopub.status.idle":"2025-06-14T14:40:03.463431Z","shell.execute_reply.started":"2025-06-14T14:40:03.455085Z","shell.execute_reply":"2025-06-14T14:40:03.462433Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_df['win_rate'] = val_df['wins'] / val_df['starts'].replace(0,1)\nval_df['podium_rate'] = val_df['podiums'] / val_df['starts'].replace(0,1)\nval_df['points_rate'] = val_df['with_points'] / val_df['starts'].replace(0,1)\nval_df['finish_rate'] = val_df['finishes'] / val_df['starts'].replace(0,1)\n\n# weather based features\nval_df['temp_diff'] = val_df['Track_Temperature_Celsius'] - val_df['Ambient_Temperature_Celsius']\nval_df['air_ground_diff'] = val_df['air'] - val_df['ground']\n\n# categorical encoding\nval_df = pd.get_dummies(val_df, columns=categorical_cols, drop_first=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:40:12.430488Z","iopub.execute_input":"2025-06-14T14:40:12.430799Z","iopub.status.idle":"2025-06-14T14:40:12.739374Z","shell.execute_reply.started":"2025-06-14T14:40:12.430779Z","shell.execute_reply":"2025-06-14T14:40:12.738319Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_val = val_df[feature_cols]\ny_val = val_df['Lap_Time_Seconds']\nx_val_scaled = scaler.transform(X_val)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:40:16.909428Z","iopub.execute_input":"2025-06-14T14:40:16.909787Z","iopub.status.idle":"2025-06-14T14:40:17.328357Z","shell.execute_reply.started":"2025-06-14T14:40:16.909762Z","shell.execute_reply":"2025-06-14T14:40:17.327268Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# from sklearn.ensemble import RandomForestRegressor\n# from sklearn.metrics import mean_squared_error, r2_score\n\nmodel = RandomForestRegressor(n_estimators=30, n_jobs = -1, random_state=42)\nmodel.fit(X_train_scaled, y)\n\ny_pred = model.predict(x_val_scaled)\n\nmse = mean_squared_error(y_val, y_pred)\nr2 = r2_score(y_val, y_pred)\n\nprint('Validation MSE: ', mse)\nprint('Validation R2: ', r2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T14:58:50.044534Z","iopub.execute_input":"2025-06-14T14:58:50.044834Z","iopub.status.idle":"2025-06-14T15:08:08.276063Z","shell.execute_reply.started":"2025-06-14T14:58:50.044812Z","shell.execute_reply":"2025-06-14T15:08:08.275040Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"importances = model.feature_importances_\nfeature_names = X.columns\n\nfeat_imp_df = pd.DataFrame({\n    'Feature': feature_names,\n    'Importance': importances\n}).sort_values(by='Importance', ascending=False)\n\nplt.figure(figsize=(12, 8))\nsns.barplot(x='Importance', y='Feature', data=feat_imp_df.head(35), palette='viridis')\nplt.title('Top 20 Important Features')\nplt.xlabel('Feature Importance Score')\nplt.ylabel('Feature')\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:10:28.534567Z","iopub.execute_input":"2025-06-14T15:10:28.534870Z","iopub.status.idle":"2025-06-14T15:10:29.078331Z","shell.execute_reply.started":"2025-06-14T15:10:28.534849Z","shell.execute_reply":"2025-06-14T15:10:29.077311Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df = pd.read_csv('/kaggle/input/burnout-datathon-ieeecsmuj/test.csv')\ntest_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:12:17.888334Z","iopub.execute_input":"2025-06-14T15:12:17.889678Z","iopub.status.idle":"2025-06-14T15:12:24.431002Z","shell.execute_reply.started":"2025-06-14T15:12:17.889634Z","shell.execute_reply":"2025-06-14T15:12:24.430015Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:12:26.714561Z","iopub.execute_input":"2025-06-14T15:12:26.714931Z","iopub.status.idle":"2025-06-14T15:12:26.721573Z","shell.execute_reply.started":"2025-06-14T15:12:26.714903Z","shell.execute_reply":"2025-06-14T15:12:26.720632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:12:28.290215Z","iopub.execute_input":"2025-06-14T15:12:28.290593Z","iopub.status.idle":"2025-06-14T15:12:28.297495Z","shell.execute_reply.started":"2025-06-14T15:12:28.290569Z","shell.execute_reply":"2025-06-14T15:12:28.296555Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ntest_df.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:12:29.878443Z","iopub.execute_input":"2025-06-14T15:12:29.878858Z","iopub.status.idle":"2025-06-14T15:12:30.346081Z","shell.execute_reply.started":"2025-06-14T15:12:29.878828Z","shell.execute_reply":"2025-06-14T15:12:30.345116Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#handling missing values in penalty column\ntest_df['Penalty'] = test_df['Penalty'].fillna('No Penalty')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:13:08.444980Z","iopub.execute_input":"2025-06-14T15:13:08.445717Z","iopub.status.idle":"2025-06-14T15:13:08.491215Z","shell.execute_reply.started":"2025-06-14T15:13:08.445687Z","shell.execute_reply":"2025-06-14T15:13:08.490103Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"penalty_mapping_test = {\n    'No Penalty': 0,\n    'DNS': 1,\n    'DNF': 2,\n    'Ride Through': 3,\n    '+3s': 4,\n    '+5s': 5\n}\ntest_df['Penalty_encoded'] = test_df['Penalty'].map(penalty_mapping_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:13:31.490493Z","iopub.execute_input":"2025-06-14T15:13:31.490882Z","iopub.status.idle":"2025-06-14T15:13:31.536728Z","shell.execute_reply.started":"2025-06-14T15:13:31.490855Z","shell.execute_reply":"2025-06-14T15:13:31.535535Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df['Penalty_encoded'].isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:13:56.634558Z","iopub.execute_input":"2025-06-14T15:13:56.634912Z","iopub.status.idle":"2025-06-14T15:13:56.643431Z","shell.execute_reply.started":"2025-06-14T15:13:56.634885Z","shell.execute_reply":"2025-06-14T15:13:56.642412Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df['win_rate'] = test_df['wins'] / test_df['starts'].replace(0,1)\ntest_df['podium_rate'] = test_df['podiums'] / test_df['starts'].replace(0,1)\ntest_df['points_rate'] = test_df['with_points'] / test_df['starts'].replace(0,1)\ntest_df['finish_rate'] = test_df['finishes'] / test_df['starts'].replace(0,1)\n\n# weather based features\ntest_df['temp_diff'] = test_df['Track_Temperature_Celsius'] - test_df['Ambient_Temperature_Celsius']\ntest_df['air_ground_diff'] = test_df['air'] - test_df['ground']\n\n# categorical encoding\ntest_df = pd.get_dummies(test_df, columns=categorical_cols, drop_first=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:15:19.485376Z","iopub.execute_input":"2025-06-14T15:15:19.486420Z","iopub.status.idle":"2025-06-14T15:15:20.889288Z","shell.execute_reply.started":"2025-06-14T15:15:19.486387Z","shell.execute_reply":"2025-06-14T15:15:20.888191Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Id = test_df['Unique ID']\ntest_df = test_df[X.columns]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:19:58.540417Z","iopub.execute_input":"2025-06-14T15:19:58.540871Z","iopub.status.idle":"2025-06-14T15:19:58.589973Z","shell.execute_reply.started":"2025-06-14T15:19:58.540840Z","shell.execute_reply":"2025-06-14T15:19:58.588984Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_scaled = scaler.transform(test_df)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:21:31.001116Z","iopub.execute_input":"2025-06-14T15:21:31.001863Z","iopub.status.idle":"2025-06-14T15:21:32.061121Z","shell.execute_reply.started":"2025-06-14T15:21:31.001800Z","shell.execute_reply":"2025-06-14T15:21:32.059726Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_predictions = model.predict(test_scaled)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:21:33.884126Z","iopub.execute_input":"2025-06-14T15:21:33.884534Z","iopub.status.idle":"2025-06-14T15:21:37.714882Z","shell.execute_reply.started":"2025-06-14T15:21:33.884504Z","shell.execute_reply":"2025-06-14T15:21:37.713730Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    'Unique ID': Id,\n    'Lap_Time_Seconds': test_predictions\n})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:21:40.679297Z","iopub.execute_input":"2025-06-14T15:21:40.679687Z","iopub.status.idle":"2025-06-14T15:21:40.687556Z","shell.execute_reply.started":"2025-06-14T15:21:40.679664Z","shell.execute_reply":"2025-06-14T15:21:40.686470Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:21:42.714209Z","iopub.execute_input":"2025-06-14T15:21:42.715048Z","iopub.status.idle":"2025-06-14T15:21:43.882581Z","shell.execute_reply.started":"2025-06-14T15:21:42.715011Z","shell.execute_reply":"2025-06-14T15:21:43.881338Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}