{"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":"import pandas as pd\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:13:02.674647Z","iopub.execute_input":"2025-06-14T05:13:02.675001Z","iopub.status.idle":"2025-06-14T05:13:04.606049Z","shell.execute_reply.started":"2025-06-14T05:13:02.674886Z","shell.execute_reply":"2025-06-14T05:13:04.605109Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df=pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/train.csv\")\ntest_df=pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/test.csv\")\nval_df=pd.read_csv(\"/kaggle/input/burnout-datathon-ieeecsmuj/val.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:15:41.458949Z","iopub.execute_input":"2025-06-14T05:15:41.459235Z","iopub.status.idle":"2025-06-14T05:15:56.716878Z","shell.execute_reply.started":"2025-06-14T05:15:41.459212Z","shell.execute_reply":"2025-06-14T05:15:56.716212Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_df.shape,test_df.shape,val_df.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:15:59.063339Z","iopub.execute_input":"2025-06-14T05:15:59.063682Z","iopub.status.idle":"2025-06-14T05:15:59.068696Z","shell.execute_reply.started":"2025-06-14T05:15:59.063659Z","shell.execute_reply":"2025-06-14T05:15:59.067905Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:18:28.603016Z","iopub.execute_input":"2025-06-14T05:18:28.603345Z","iopub.status.idle":"2025-06-14T05:18:28.642892Z","shell.execute_reply.started":"2025-06-14T05:18:28.603321Z","shell.execute_reply":"2025-06-14T05:18:28.642169Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.nunique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:15:15.945947Z","iopub.execute_input":"2025-06-14T07:15:15.946515Z","iopub.status.idle":"2025-06-14T07:15:19.319952Z","shell.execute_reply.started":"2025-06-14T07:15:15.946455Z","shell.execute_reply":"2025-06-14T07:15:19.319029Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\n# Assuming train_df and val_df are already defined\ntrain_df = pd.concat([train_df, val_df], ignore_index=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:21:05.392235Z","iopub.execute_input":"2025-06-14T05:21:05.392577Z","iopub.status.idle":"2025-06-14T05:21:05.856148Z","shell.execute_reply.started":"2025-06-14T05:21:05.392553Z","shell.execute_reply":"2025-06-14T05:21:05.855316Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_df.shape,test_df.shape,val_df.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:21:15.323861Z","iopub.execute_input":"2025-06-14T05:21:15.324141Z","iopub.status.idle":"2025-06-14T05:21:15.328861Z","shell.execute_reply.started":"2025-06-14T05:21:15.324119Z","shell.execute_reply":"2025-06-14T05:21:15.328097Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.nunique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:21:31.874496Z","iopub.execute_input":"2025-06-14T05:21:31.875225Z","iopub.status.idle":"2025-06-14T05:21:34.250637Z","shell.execute_reply.started":"2025-06-14T05:21:31.875203Z","shell.execute_reply":"2025-06-14T05:21:34.249778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:22:55.432047Z","iopub.execute_input":"2025-06-14T05:22:55.432356Z","iopub.status.idle":"2025-06-14T05:22:55.440015Z","shell.execute_reply.started":"2025-06-14T05:22:55.432335Z","shell.execute_reply":"2025-06-14T05:22:55.439265Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:24:23.492787Z","iopub.execute_input":"2025-06-14T05:24:23.493094Z","iopub.status.idle":"2025-06-14T05:24:25.092899Z","shell.execute_reply.started":"2025-06-14T05:24:23.493072Z","shell.execute_reply":"2025-06-14T05:24:25.091942Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df=train_df.fillna(0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:24:44.919533Z","iopub.execute_input":"2025-06-14T05:24:44.919816Z","iopub.status.idle":"2025-06-14T05:24:47.359789Z","shell.execute_reply.started":"2025-06-14T05:24:44.919797Z","shell.execute_reply":"2025-06-14T05:24:47.358887Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\nfrom catboost import CatBoostRegressor\nimport time\n\n# Target column\ntarget_col = 'Lap_Time_Seconds'\n\n# Drop rows with missing target\ntrain_df = train_df.dropna(subset=[target_col])\n\n# Split features and target\nX = train_df.drop(columns=[target_col])\ny = train_df[target_col]\n\n# Split into training and validation sets\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Identify categorical features (CatBoost handles them natively)\ncat_features = X.select_dtypes(include=['object', 'category']).columns.tolist()\n\n# Optional: Fill missing values\nX_train = X_train.fillna(-999)\nX_val = X_val.fillna(-999)\n\n# Initialize CatBoost Regressor\nmodel = CatBoostRegressor(\n    iterations=1000,\n    learning_rate=0.05,\n    depth=6,\n    eval_metric='RMSE',\n    random_seed=42,\n    verbose=100\n)\n\n# Record training start time\nstart_time = time.time()\n\n# Train model\nmodel.fit(X_train, y_train, cat_features=cat_features, eval_set=(X_val, y_val), early_stopping_rounds=50)\n\n# Record training end time\nend_time = time.time()\n\n# Predict and evaluate RMSE\ny_pred = model.predict(X_val)\nrmse = mean_squared_error(y_val, y_pred, squared=False)\ntraining_time = end_time - start_time\n\n# Print results\nprint(f\"\\nValidation RMSE: {rmse:.4f}\")\nprint(f\"Training Time: {training_time:.2f} seconds\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:25:06.582376Z","iopub.execute_input":"2025-06-14T05:25:06.582723Z","iopub.status.idle":"2025-06-14T06:03:44.875760Z","shell.execute_reply.started":"2025-06-14T05:25:06.582694Z","shell.execute_reply":"2025-06-14T06:03:44.873639Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\nfrom catboost import CatBoostRegressor\nimport time\n\n# Target column\ntarget_col = 'Lap_Time_Seconds'\n\n# Drop rows with missing target\ntrain_df = train_df.dropna(subset=[target_col])\n\n# Treat ID-like numeric columns as categorical by converting them to string\nid_like_cats = ['Rider_ID', 'Rider', 'Team', 'Bike']\nfor col in id_like_cats:\n    if col in train_df.columns:\n        train_df[col] = train_df[col].astype(str)\n\n# Split features and target\nX = train_df.drop(columns=[target_col])\ny = train_df[target_col]\n\n# Split into training and validation sets\nX_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Identify categorical features for CatBoost\ncat_features = X.select_dtypes(include=['object', 'category']).columns.tolist()\n\n# Fill missing values (CatBoost can handle missing values too, but filling ensures no surprises)\nX_train = X_train.fillna(-999)\nX_val = X_val.fillna(-999)\n\n# Initialize CatBoost Regressor\nmodel = CatBoostRegressor(\n    iterations=1000,\n    learning_rate=0.05,\n    depth=6,\n    eval_metric='RMSE',\n    random_seed=42,\n    verbose=100\n)\n\n# Record training start time\nstart_time = time.time()\n\n# Train model\nmodel.fit(X_train, y_train, cat_features=cat_features, eval_set=(X_val, y_val), early_stopping_rounds=50)\n\n# Record training end time\nend_time = time.time()\n\n# Predict and evaluate RMSE\ny_pred = model.predict(X_val)\nrmse = mean_squared_error(y_val, y_pred, squared=False)\ntraining_time = end_time - start_time\n\n# Print results\nprint(f\"\\nValidation RMSE: {rmse:.4f}\")\nprint(f\"Training Time: {training_time:.2f} seconds\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:06:40.978563Z","iopub.execute_input":"2025-06-14T06:06:40.980189Z","iopub.status.idle":"2025-06-14T06:59:00.668028Z","shell.execute_reply.started":"2025-06-14T06:06:40.980140Z","shell.execute_reply":"2025-06-14T06:59:00.667099Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}