{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":82611,"databundleVersionId":9553358,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport xgboost as xgb\nfrom sklearn.model_selection import GridSearchCV, train_test_split\nfrom xgboost import XGBRegressor\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-04T17:07:04.772619Z","iopub.execute_input":"2024-10-04T17:07:04.773058Z","iopub.status.idle":"2024-10-04T17:07:04.779721Z","shell.execute_reply.started":"2024-10-04T17:07:04.773009Z","shell.execute_reply":"2024-10-04T17:07:04.778542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.simplefilter(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2024-10-04T15:53:23.301434Z","iopub.execute_input":"2024-10-04T15:53:23.301875Z","iopub.status.idle":"2024-10-04T15:53:23.308040Z","shell.execute_reply.started":"2024-10-04T15:53:23.301827Z","shell.execute_reply":"2024-10-04T15:53:23.306620Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/brist1d/train.csv\")\ntest=pd.read_csv(\"/kaggle/input/brist1d/test.csv\")\nsubmission_df = pd.read_csv('/kaggle/input/brist1d/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:23:34.031687Z","iopub.execute_input":"2024-10-04T16:23:34.032132Z","iopub.status.idle":"2024-10-04T16:23:45.962461Z","shell.execute_reply.started":"2024-10-04T16:23:34.032087Z","shell.execute_reply":"2024-10-04T16:23:45.961454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-04T15:53:55.777436Z","iopub.execute_input":"2024-10-04T15:53:55.778154Z","iopub.status.idle":"2024-10-04T15:53:55.822073Z","shell.execute_reply.started":"2024-10-04T15:53:55.778090Z","shell.execute_reply":"2024-10-04T15:53:55.820770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:25:53.239984Z","iopub.execute_input":"2024-10-04T16:25:53.240485Z","iopub.status.idle":"2024-10-04T16:25:53.278753Z","shell.execute_reply.started":"2024-10-04T16:25:53.240439Z","shell.execute_reply":"2024-10-04T16:25:53.277217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:25:55.396786Z","iopub.execute_input":"2024-10-04T16:25:55.397247Z","iopub.status.idle":"2024-10-04T16:25:56.102652Z","shell.execute_reply.started":"2024-10-04T16:25:55.397199Z","shell.execute_reply":"2024-10-04T16:25:56.101547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['time'] = pd.to_datetime(train['time'], format='%H:%M:%S')\ntest['time'] = pd.to_datetime(test['time'], format='%H:%M:%S')","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:41:05.372592Z","iopub.execute_input":"2024-10-04T16:41:05.373113Z","iopub.status.idle":"2024-10-04T16:41:05.408457Z","shell.execute_reply.started":"2024-10-04T16:41:05.373066Z","shell.execute_reply":"2024-10-04T16:41:05.407356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['hour'] = train['time'].dt.hour\ntrain['minute'] = train['time'].dt.minute\ntest['hour'] = test['time'].dt.hour\ntest['minute'] = test['time'].dt.minute","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:41:08.141256Z","iopub.execute_input":"2024-10-04T16:41:08.141736Z","iopub.status.idle":"2024-10-04T16:41:08.161459Z","shell.execute_reply.started":"2024-10-04T16:41:08.141691Z","shell.execute_reply":"2024-10-04T16:41:08.160309Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.drop('time',axis=1,inplace=True)\ntest.drop('time',axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:41:10.758870Z","iopub.execute_input":"2024-10-04T16:41:10.759342Z","iopub.status.idle":"2024-10-04T16:41:11.160149Z","shell.execute_reply.started":"2024-10-04T16:41:10.759287Z","shell.execute_reply":"2024-10-04T16:41:11.159024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_cols = train.select_dtypes(include=['float64', 'int64']).columns.tolist()\nnumerical_cols.remove('bg+1:00')\ncategorical_cols = [col for col in train.columns if 'activity' in col]","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:55:06.859014Z","iopub.execute_input":"2024-10-04T16:55:06.859570Z","iopub.status.idle":"2024-10-04T16:55:07.107479Z","shell.execute_reply.started":"2024-10-04T16:55:06.859523Z","shell.execute_reply":"2024-10-04T16:55:07.106346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Impute missing numerical values\nimputer = SimpleImputer(strategy='mean')\ntrain[numerical_cols] = imputer.fit_transform(train[numerical_cols])\ntest[numerical_cols] = imputer.transform(test[numerical_cols])","metadata":{"execution":{"iopub.status.busy":"2024-10-04T16:56:10.431834Z","iopub.execute_input":"2024-10-04T16:56:10.432872Z","iopub.status.idle":"2024-10-04T16:56:14.254027Z","shell.execute_reply.started":"2024-10-04T16:56:10.432821Z","shell.execute_reply":"2024-10-04T16:56:14.252848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Encode categorical variables\nfor col in categorical_cols:\n    train[col] = train[col].fillna('None')\n    test[col] = test[col].fillna('None')\n    le = LabelEncoder()\n    combined_data = pd.concat([train[col], test[col]], axis=0)\n    le.fit(combined_data)\n    train[col] = le.transform(train[col])\n    test[col] = le.transform(test[col])","metadata":{"execution":{"iopub.status.busy":"2024-10-04T17:01:19.852507Z","iopub.execute_input":"2024-10-04T17:01:19.852981Z","iopub.status.idle":"2024-10-04T17:01:24.762387Z","shell.execute_reply.started":"2024-10-04T17:01:19.852935Z","shell.execute_reply":"2024-10-04T17:01:24.761173Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = StandardScaler()\ntrain[numerical_cols] = scaler.fit_transform(train[numerical_cols])\ntest[numerical_cols] = scaler.transform(test[numerical_cols])","metadata":{"execution":{"iopub.status.busy":"2024-10-04T17:01:26.296247Z","iopub.execute_input":"2024-10-04T17:01:26.297679Z","iopub.status.idle":"2024-10-04T17:01:28.701078Z","shell.execute_reply.started":"2024-10-04T17:01:26.297613Z","shell.execute_reply":"2024-10-04T17:01:28.699788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Prepare data for modeling\nX_train = train.drop(['id', 'p_num', 'bg+1:00'], axis=1)\ny_train = train['bg+1:00']\nX_test = test.drop(['id', 'p_num'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-10-04T17:01:43.085485Z","iopub.execute_input":"2024-10-04T17:01:43.085937Z","iopub.status.idle":"2024-10-04T17:01:43.891627Z","shell.execute_reply.started":"2024-10-04T17:01:43.085892Z","shell.execute_reply":"2024-10-04T17:01:43.890444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_split, X_val_split, y_train_split, y_val_split = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n    \n# Train an XGBoost model\nxgb_model = XGBRegressor(objective='reg:squarederror', n_estimators=100, random_state=42)\nxgb_model.fit(X_train_split, y_train_split)\nxgb_predictions = xgb_model.predict(X_val_split)\nxgb_rmse = np.sqrt(mean_squared_error(y_val_split, xgb_predictions))\nprint(f\"XGBoost RMSE: {xgb_rmse}\")","metadata":{"execution":{"iopub.status.busy":"2024-10-04T17:05:00.123353Z","iopub.execute_input":"2024-10-04T17:05:00.123805Z","iopub.status.idle":"2024-10-04T17:05:26.752287Z","shell.execute_reply.started":"2024-10-04T17:05:00.123748Z","shell.execute_reply":"2024-10-04T17:05:26.751289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_predictions = xgb_model.predict(X_test)\n\n# Create a submission DataFrame\nsubmission_df['bg+1:00'] = test_predictions\n\n# Save the submission file\nsubmission_df.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-10-04T17:06:32.483460Z","iopub.execute_input":"2024-10-04T17:06:32.484151Z","iopub.status.idle":"2024-10-04T17:06:32.615254Z","shell.execute_reply.started":"2024-10-04T17:06:32.484067Z","shell.execute_reply":"2024-10-04T17:06:32.614330Z"},"trusted":true},"execution_count":null,"outputs":[]}]}