{"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 pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split, GridSearchCV\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score\nfrom sklearn.ensemble import RandomForestRegressor\nfrom xgboost import XGBRegressor\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:00:25.027061Z","iopub.execute_input":"2025-06-14T15:00:25.027369Z","iopub.status.idle":"2025-06-14T15:00:29.435643Z","shell.execute_reply.started":"2025-06-14T15:00:25.027342Z","shell.execute_reply":"2025-06-14T15:00:29.434760Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/test.csv\")\nval = pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/val.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:00:47.401826Z","iopub.execute_input":"2025-06-14T15:00:47.402149Z","iopub.status.idle":"2025-06-14T15:01:09.126855Z","shell.execute_reply.started":"2025-06-14T15:00:47.402124Z","shell.execute_reply":"2025-06-14T15:01:09.126011Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.info())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:01:58.876737Z","iopub.execute_input":"2025-06-14T15:01:58.877034Z","iopub.status.idle":"2025-06-14T15:01:58.904012Z","shell.execute_reply.started":"2025-06-14T15:01:58.877014Z","shell.execute_reply":"2025-06-14T15:01:58.903045Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.describe())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:02:25.106964Z","iopub.execute_input":"2025-06-14T15:02:25.107581Z","iopub.status.idle":"2025-06-14T15:02:27.384540Z","shell.execute_reply.started":"2025-06-14T15:02:25.107556Z","shell.execute_reply":"2025-06-14T15:02:27.383781Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.isnull().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:02:34.342166Z","iopub.execute_input":"2025-06-14T15:02:34.342943Z","iopub.status.idle":"2025-06-14T15:02:35.636172Z","shell.execute_reply.started":"2025-06-14T15:02:34.342918Z","shell.execute_reply":"2025-06-14T15:02:35.635420Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:03:14.527146Z","iopub.execute_input":"2025-06-14T15:03:14.527471Z","iopub.status.idle":"2025-06-14T15:03:14.534098Z","shell.execute_reply.started":"2025-06-14T15:03:14.527450Z","shell.execute_reply":"2025-06-14T15:03:14.533320Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:02:53.946811Z","iopub.execute_input":"2025-06-14T15:02:53.947091Z","iopub.status.idle":"2025-06-14T15:02:54.333185Z","shell.execute_reply.started":"2025-06-14T15:02:53.947071Z","shell.execute_reply":"2025-06-14T15:02:54.332481Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:03:21.347745Z","iopub.execute_input":"2025-06-14T15:03:21.348085Z","iopub.status.idle":"2025-06-14T15:03:21.353593Z","shell.execute_reply.started":"2025-06-14T15:03:21.348060Z","shell.execute_reply":"2025-06-14T15:03:21.352871Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.describe","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:03:26.206616Z","iopub.execute_input":"2025-06-14T15:03:26.206925Z","iopub.status.idle":"2025-06-14T15:03:26.270511Z","shell.execute_reply.started":"2025-06-14T15:03:26.206894Z","shell.execute_reply":"2025-06-14T15:03:26.269839Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.histplot(train['Lap_Time_Seconds'], kde=True)\nplt.title(\"Distribution of Lap Time\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:03:39.816624Z","iopub.execute_input":"2025-06-14T15:03:39.817140Z","iopub.status.idle":"2025-06-14T15:03:48.176662Z","shell.execute_reply.started":"2025-06-14T15:03:39.817115Z","shell.execute_reply":"2025-06-14T15:03:48.175661Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(x=train['Lap_Time_Seconds'])\nplt.title(\"Boxplot of Lap Time\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:03:50.226719Z","iopub.execute_input":"2025-06-14T15:03:50.227437Z","iopub.status.idle":"2025-06-14T15:03:50.442143Z","shell.execute_reply.started":"2025-06-14T15:03:50.227415Z","shell.execute_reply":"2025-06-14T15:03:50.441384Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numeric_features = train.select_dtypes(include=[np.number])\nsns.heatmap(numeric_features.corr(), annot=True, fmt=\".2f\")\nplt.title(\"Feature Correlation\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:04:06.517534Z","iopub.execute_input":"2025-06-14T15:04:06.517860Z","iopub.status.idle":"2025-06-14T15:04:14.380749Z","shell.execute_reply.started":"2025-06-14T15:04:06.517827Z","shell.execute_reply":"2025-06-14T15:04:14.379828Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train['Race_Status'] = train['position'].map({-1: 'DNF', -2: 'DNS', -3: 'DSQ', -4: 'DNQ'}).fillna('Finished')\ntrain['Finish_Rate'] = train['finishes'] / train['starts']\ntrain['Points_per_Race'] = train['Championship_Points'] / train['starts']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:05:41.536853Z","iopub.execute_input":"2025-06-14T15:05:41.537776Z","iopub.status.idle":"2025-06-14T15:05:41.714940Z","shell.execute_reply.started":"2025-06-14T15:05:41.537751Z","shell.execute_reply":"2025-06-14T15:05:41.714014Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cols_to_drop = ['Unique ID', 'Rider_ID', 'rider', 'team', 'bike', 'rider_name', 'team_name', 'bike_name', 'position']\ntrain.drop(columns=cols_to_drop, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:06:38.186630Z","iopub.execute_input":"2025-06-14T15:06:38.187286Z","iopub.status.idle":"2025-06-14T15:06:38.600903Z","shell.execute_reply.started":"2025-06-14T15:06:38.187262Z","shell.execute_reply":"2025-06-14T15:06:38.599930Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categorical_cols = train.select_dtypes(include='object').columns\ntrain = pd.get_dummies(train, columns=categorical_cols, drop_first=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:06:59.331846Z","iopub.execute_input":"2025-06-14T15:06:59.332153Z","iopub.status.idle":"2025-06-14T15:07:02.703286Z","shell.execute_reply.started":"2025-06-14T15:06:59.332129Z","shell.execute_reply":"2025-06-14T15:07:02.702389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"scaler = StandardScaler()\nnumeric_cols = train.select_dtypes(include=[np.number]).drop(columns='Lap_Time_Seconds').columns\ntrain[numeric_cols] = scaler.fit_transform(train[numeric_cols])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:07:12.177680Z","iopub.execute_input":"2025-06-14T15:07:12.178382Z","iopub.status.idle":"2025-06-14T15:07:13.805398Z","shell.execute_reply.started":"2025-06-14T15:07:12.178362Z","shell.execute_reply":"2025-06-14T15:07:13.804695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = train.drop(\"Lap_Time_Seconds\", axis=1)\ny = train[\"Lap_Time_Seconds\"]\nX_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.2, random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:07:25.246815Z","iopub.execute_input":"2025-06-14T15:07:25.247540Z","iopub.status.idle":"2025-06-14T15:07:28.200306Z","shell.execute_reply.started":"2025-06-14T15:07:25.247517Z","shell.execute_reply":"2025-06-14T15:07:28.199579Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = XGBRegressor()\nmodel.fit(X_train, y_train)\npreds = model.predict(X_valid)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:08:21.587542Z","iopub.execute_input":"2025-06-14T15:08:21.588355Z","iopub.status.idle":"2025-06-14T15:09:17.036292Z","shell.execute_reply.started":"2025-06-14T15:08:21.588331Z","shell.execute_reply":"2025-06-14T15:09:17.035600Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"MAE:\", mean_absolute_error(y_valid, preds))\nprint(\"RMSE:\", np.sqrt(mean_squared_error(y_valid, preds)))\nprint(\"R2 Score:\", r2_score(y_valid, preds))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:09:28.162448Z","iopub.execute_input":"2025-06-14T15:09:28.162763Z","iopub.status.idle":"2025-06-14T15:09:28.181415Z","shell.execute_reply.started":"2025-06-14T15:09:28.162742Z","shell.execute_reply":"2025-06-14T15:09:28.180491Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val['Race_Status'] = val['position'].map({-1: 'DNF', -2: 'DNS', -3: 'DSQ', -4: 'DNQ'}).fillna('Finished')\nval['Finish_Rate'] = val['finishes'] / val['starts']\nval['Points_per_Race'] = val['Championship_Points'] / val['starts']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:10:32.328386Z","iopub.execute_input":"2025-06-14T15:10:32.328682Z","iopub.status.idle":"2025-06-14T15:10:32.365583Z","shell.execute_reply.started":"2025-06-14T15:10:32.328660Z","shell.execute_reply":"2025-06-14T15:10:32.364822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cols_to_drop = ['Unique ID', 'Rider_ID', 'rider', 'team', 'bike',\n'rider_name', 'team_name', 'bike_name', 'position']\nval.drop(columns=cols_to_drop, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:11:09.142195Z","iopub.execute_input":"2025-06-14T15:11:09.143015Z","iopub.status.idle":"2025-06-14T15:11:09.189502Z","shell.execute_reply.started":"2025-06-14T15:11:09.142987Z","shell.execute_reply":"2025-06-14T15:11:09.188602Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val = pd.get_dummies(val, drop_first=True)\nval = val.reindex(columns=X_train.columns, fill_value=0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:11:31.763149Z","iopub.execute_input":"2025-06-14T15:11:31.763482Z","iopub.status.idle":"2025-06-14T15:11:32.127977Z","shell.execute_reply.started":"2025-06-14T15:11:31.763460Z","shell.execute_reply":"2025-06-14T15:11:32.127000Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val[numeric_cols] = scaler.transform(val[numeric_cols]) ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:11:43.532218Z","iopub.execute_input":"2025-06-14T15:11:43.532589Z","iopub.status.idle":"2025-06-14T15:11:43.629188Z","shell.execute_reply.started":"2025-06-14T15:11:43.532567Z","shell.execute_reply":"2025-06-14T15:11:43.628528Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_val_true = val_original_target = pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/val.csv\")[\"Lap_Time_Seconds\"]\ny_val_pred = model.predict(val)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:12:53.963502Z","iopub.execute_input":"2025-06-14T15:12:53.963802Z","iopub.status.idle":"2025-06-14T15:12:59.207252Z","shell.execute_reply.started":"2025-06-14T15:12:53.963780Z","shell.execute_reply":"2025-06-14T15:12:59.206601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mae = mean_absolute_error(y_val_true, y_val_pred)\nrmse = np.sqrt(mean_squared_error(y_val_true, y_val_pred))\nr2 = r2_score(y_val_true, y_val_pred)\n\nprint(\"Validation on val.csv:\")\nprint(\"MAE:\", mae)\nprint(\"RMSE:\", rmse)\nprint(\"R² Score:\", r2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:13:17.522493Z","iopub.execute_input":"2025-06-14T15:13:17.522798Z","iopub.status.idle":"2025-06-14T15:13:17.534980Z","shell.execute_reply.started":"2025-06-14T15:13:17.522777Z","shell.execute_reply":"2025-06-14T15:13:17.534100Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test['Race_Status'] = test['position'].map({-1: 'DNF', -2: 'DNS', -3: 'DSQ', -4: 'DNQ'}).fillna('Finished')\ntest['Finish_Rate'] = test['finishes'] / test['starts']\ntest['Points_per_Race'] = test['Championship_Points'] / test['starts']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:13:54.292460Z","iopub.execute_input":"2025-06-14T15:13:54.292753Z","iopub.status.idle":"2025-06-14T15:13:54.349889Z","shell.execute_reply.started":"2025-06-14T15:13:54.292735Z","shell.execute_reply":"2025-06-14T15:13:54.348980Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cols_to_drop = ['Unique ID', 'Rider_ID', 'rider', 'team', 'bike',\n'rider_name', 'team_name', 'bike_name', 'position']\ntest.drop(columns=cols_to_drop, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:14:25.657840Z","iopub.execute_input":"2025-06-14T15:14:25.658163Z","iopub.status.idle":"2025-06-14T15:14:25.748847Z","shell.execute_reply.started":"2025-06-14T15:14:25.658138Z","shell.execute_reply":"2025-06-14T15:14:25.747963Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.get_dummies(test, drop_first=True)\ntest = test.reindex(columns=X_train.columns, fill_value=0) # X_train is from train/test split","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:14:38.382321Z","iopub.execute_input":"2025-06-14T15:14:38.383137Z","iopub.status.idle":"2025-06-14T15:14:39.238015Z","shell.execute_reply.started":"2025-06-14T15:14:38.383106Z","shell.execute_reply":"2025-06-14T15:14:39.237299Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test[numeric_cols] = scaler.transform(test[numeric_cols])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:14:49.072952Z","iopub.execute_input":"2025-06-14T15:14:49.073479Z","iopub.status.idle":"2025-06-14T15:14:49.264301Z","shell.execute_reply.started":"2025-06-14T15:14:49.073455Z","shell.execute_reply":"2025-06-14T15:14:49.263339Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = model.predict(test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:15:03.553080Z","iopub.execute_input":"2025-06-14T15:15:03.553417Z","iopub.status.idle":"2025-06-14T15:15:11.211922Z","shell.execute_reply.started":"2025-06-14T15:15:03.553393Z","shell.execute_reply":"2025-06-14T15:15:11.211295Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.read_csv('/kaggle/input/burnout-datathon-ieeecsmuj/sample_submission.csv')\nsubmission['Lap_Time_Seconds'] = predictions\nsubmission.to_csv('my_submission.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T15:16:32.203539Z","iopub.execute_input":"2025-06-14T15:16:32.203851Z","iopub.status.idle":"2025-06-14T15:16:33.323952Z","shell.execute_reply.started":"2025-06-14T15:16:32.203823Z","shell.execute_reply":"2025-06-14T15:16:33.323048Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}