{"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 xgboost as xgb\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\nimport pandas as pd\nimport gc","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:13:17.142051Z","iopub.execute_input":"2025-06-14T11:13:17.142452Z","iopub.status.idle":"2025-06-14T11:13:17.147680Z","shell.execute_reply.started":"2025-06-14T11:13:17.142426Z","shell.execute_reply":"2025-06-14T11:13:17.146680Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/burnout-datathon-ieeecsmuj/train.csv', low_memory=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:13:18.165063Z","iopub.execute_input":"2025-06-14T11:13:18.165505Z","iopub.status.idle":"2025-06-14T11:13:33.969495Z","shell.execute_reply.started":"2025-06-14T11:13:18.165474Z","shell.execute_reply":"2025-06-14T11:13:33.968587Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in df.select_dtypes(include=['object']).columns:\n    df[col] = df[col].astype('category')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:13:48.026684Z","iopub.execute_input":"2025-06-14T11:13:48.027141Z","iopub.status.idle":"2025-06-14T11:13:48.034452Z","shell.execute_reply.started":"2025-06-14T11:13:48.027102Z","shell.execute_reply":"2025-06-14T11:13:48.032707Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['team_name'] = df['team_name'].cat.add_categories('Unknown').fillna('Unknown')\ndf = df.drop(columns=['rider_name'], errors='ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:14:07.892630Z","iopub.execute_input":"2025-06-14T11:14:07.893202Z","iopub.status.idle":"2025-06-14T11:14:08.254672Z","shell.execute_reply.started":"2025-06-14T11:14:07.893069Z","shell.execute_reply":"2025-06-14T11:14:08.253497Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = df.drop(columns=['Lap_Time_Seconds'])\ny = df['Lap_Time_Seconds']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:14:10.338732Z","iopub.execute_input":"2025-06-14T11:14:10.339100Z","iopub.status.idle":"2025-06-14T11:14:10.638018Z","shell.execute_reply.started":"2025-06-14T11:14:10.339079Z","shell.execute_reply":"2025-06-14T11:14:10.636823Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in X.select_dtypes(include=['category']).columns:\n    X[col] = X[col].cat.codes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:14:11.739884Z","iopub.execute_input":"2025-06-14T11:14:11.740353Z","iopub.status.idle":"2025-06-14T11:14:11.779610Z","shell.execute_reply.started":"2025-06-14T11:14:11.740306Z","shell.execute_reply":"2025-06-14T11:14:11.778613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.05, random_state=42)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:15:11.925214Z","iopub.execute_input":"2025-06-14T11:15:11.925658Z","iopub.status.idle":"2025-06-14T11:15:13.330134Z","shell.execute_reply.started":"2025-06-14T11:15:11.925629Z","shell.execute_reply":"2025-06-14T11:15:13.329042Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = xgb.XGBRegressor(\n    objective='reg:squarederror',\n    n_estimators=300,\n    learning_rate=0.1,\n    max_depth=6,\n    eval_metric='rmse',          \n    early_stopping_rounds=20, \n    # other parameters...\n    random_state=42\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:15:14.372581Z","iopub.execute_input":"2025-06-14T11:15:14.372966Z","iopub.status.idle":"2025-06-14T11:15:14.378870Z","shell.execute_reply.started":"2025-06-14T11:15:14.372941Z","shell.execute_reply":"2025-06-14T11:15:14.377799Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(\n    X_train, y_train,\n    eval_set=[(X_val, y_val)],    # Keep eval_set in fit()\n    verbose=False\n)\ndel X_train, y_train\ngc.collect()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:15:16.806821Z","iopub.execute_input":"2025-06-14T11:15:16.808119Z","iopub.status.idle":"2025-06-14T11:16:03.684168Z","shell.execute_reply.started":"2025-06-14T11:15:16.808057Z","shell.execute_reply":"2025-06-14T11:16:03.683202Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds = model.predict(X_val)\nrmse = mean_squared_error(y_val, preds, squared=False)\nprint(f\"XGBoost RMSE: {rmse:.4f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T11:16:04.015010Z","iopub.execute_input":"2025-06-14T11:16:04.015268Z","iopub.status.idle":"2025-06-14T11:16:04.355232Z","shell.execute_reply.started":"2025-06-14T11:16:04.015249Z","shell.execute_reply":"2025-06-14T11:16:04.354478Z"}},"outputs":[],"execution_count":null}]}