{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.15","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"tpu1vmV38","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":"markdown","source":" # Importing The Library\r\n","metadata":{}},{"cell_type":"code","source":"import pandas as pd \nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler, OneHotEncoder\nimport warnings\nfrom sklearn.linear_model import LinearRegression,Lasso, Ridge,ElasticNet\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.svm import SVR\nfrom sklearn.neighbors import KNeighborsRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.metrics import mean_squared_error , mean_absolute_error\nwarnings.filterwarnings('ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:20.074268Z","iopub.execute_input":"2024-12-10T18:50:20.075119Z","iopub.status.idle":"2024-12-10T18:50:21.512233Z","shell.execute_reply.started":"2024-12-10T18:50:20.075072Z","shell.execute_reply":"2024-12-10T18:50:21.511250Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/brist1d/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/brist1d/test.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:21.514208Z","iopub.execute_input":"2024-12-10T18:50:21.514856Z","iopub.status.idle":"2024-12-10T18:50:31.694755Z","shell.execute_reply.started":"2024-12-10T18:50:21.514820Z","shell.execute_reply":"2024-12-10T18:50:31.693708Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head(2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:31.696006Z","iopub.execute_input":"2024-12-10T18:50:31.696315Z","iopub.status.idle":"2024-12-10T18:50:31.720334Z","shell.execute_reply.started":"2024-12-10T18:50:31.696290Z","shell.execute_reply":"2024-12-10T18:50:31.719606Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.head(2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:31.721265Z","iopub.execute_input":"2024-12-10T18:50:31.721508Z","iopub.status.idle":"2024-12-10T18:50:31.737271Z","shell.execute_reply.started":"2024-12-10T18:50:31.721483Z","shell.execute_reply":"2024-12-10T18:50:31.736541Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Train_df: \", train_df.shape)\nprint(\"Test_df: \",test_df.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:31.739359Z","iopub.execute_input":"2024-12-10T18:50:31.739618Z","iopub.status.idle":"2024-12-10T18:50:31.746001Z","shell.execute_reply.started":"2024-12-10T18:50:31.739596Z","shell.execute_reply":"2024-12-10T18:50:31.745166Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()\nprint(\"\\n\")\nprint(\"----------------------------\")\nprint(f\"Train_df Missing Values: \\n \",train_df.isnull().mean() *100)\nprint(\"\\n\")\nprint(\"----------------------------\")\nprint(f\"Train_df Duplicated Values: \",train_df.duplicated().mean() *100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:31.746873Z","iopub.execute_input":"2024-12-10T18:50:31.747091Z","iopub.status.idle":"2024-12-10T18:50:34.404587Z","shell.execute_reply.started":"2024-12-10T18:50:31.747069Z","shell.execute_reply":"2024-12-10T18:50:34.403581Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.info()\nprint(\"\\n\")\nprint(\"----------------------------\")\nprint(f\"Train_df Missing Values: \\n \",test_df.isnull().mean() *100)\nprint(\"\\n\")\nprint(\"----------------------------\")\nprint(f\"Train_df Duplicated Values: \",test_df.duplicated().mean() *100)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:34.405840Z","iopub.execute_input":"2024-12-10T18:50:34.406151Z","iopub.status.idle":"2024-12-10T18:50:34.509425Z","shell.execute_reply.started":"2024-12-10T18:50:34.406122Z","shell.execute_reply":"2024-12-10T18:50:34.508541Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# check the missing values","metadata":{}},{"cell_type":"code","source":"# checking for null values\nfor col in train_df:\n    print(f\"{col} has {train_df[col].isnull().mean()*100} missing values\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:34.510559Z","iopub.execute_input":"2024-12-10T18:50:34.511170Z","iopub.status.idle":"2024-12-10T18:50:35.028923Z","shell.execute_reply.started":"2024-12-10T18:50:34.511135Z","shell.execute_reply":"2024-12-10T18:50:35.028031Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:35.030008Z","iopub.execute_input":"2024-12-10T18:50:35.030294Z","iopub.status.idle":"2024-12-10T18:50:38.317182Z","shell.execute_reply.started":"2024-12-10T18:50:35.030266Z","shell.execute_reply":"2024-12-10T18:50:38.316338Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df['time'] = pd.to_datetime(train_df['time'], format='%H:%M:%S')\ntest_df['time'] = pd.to_datetime(test_df['time'], format='%H:%M:%S')\n\ntrain_df['hour'] = train_df['time'].dt.hour\ntrain_df['minute'] = train_df['time'].dt.minute\ntest_df['hour'] = test_df['time'].dt.hour\ntest_df['minute'] = test_df['time'].dt.minute\n\ntrain_df.drop('time', axis=1, inplace=True)\ntest_df.drop('time', axis=1, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:38.318299Z","iopub.execute_input":"2024-12-10T18:50:38.318609Z","iopub.status.idle":"2024-12-10T18:50:38.670148Z","shell.execute_reply.started":"2024-12-10T18:50:38.318579Z","shell.execute_reply":"2024-12-10T18:50:38.669161Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Fill the missing values","metadata":{}},{"cell_type":"code","source":"object_columns = train_df.select_dtypes(include=\"object\").columns\n\nprint(f\"Object columns: {object_columns.shape[0]}\")\nprint()\n\n# Displaying the count of null values for each object column\nfor col in object_columns:\n    print(f\"{col} has {train_df[col].isnull().mean()*100} missing values\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:38.671436Z","iopub.execute_input":"2024-12-10T18:50:38.671758Z","iopub.status.idle":"2024-12-10T18:50:39.609282Z","shell.execute_reply.started":"2024-12-10T18:50:38.671729Z","shell.execute_reply":"2024-12-10T18:50:39.608411Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"object_columns = test_df.select_dtypes(include=\"object\").columns\n\nprint(f\"Object columns: {object_columns.shape[0]}\")\nprint()\n\n# Displaying the count of null values for each object column\nfor col in object_columns:\n    print(f\"{col} has {test_df[col].isnull().mean()*100} missing values\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:39.610460Z","iopub.execute_input":"2024-12-10T18:50:39.610767Z","iopub.status.idle":"2024-12-10T18:50:39.642104Z","shell.execute_reply.started":"2024-12-10T18:50:39.610740Z","shell.execute_reply":"2024-12-10T18:50:39.641202Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in object_columns:\n    train_df[col].fillna(\"Missing\", inplace=True)\n\nfor col in object_columns:\n    test_df[col].fillna(\"Missing\", inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:39.643251Z","iopub.execute_input":"2024-12-10T18:50:39.643660Z","iopub.status.idle":"2024-12-10T18:50:40.226436Z","shell.execute_reply.started":"2024-12-10T18:50:39.643630Z","shell.execute_reply":"2024-12-10T18:50:40.225197Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"number_columns_train = train_df.select_dtypes(include=[\"float64\", \"int64\"])\nnumber_columns_test = test_df.select_dtypes(include=[\"float64\", \"int64\"])\n\n\nprint(f\"numerical Columns : {number_columns_train.shape[1]}\")\n\nprint()\n# Displaying the count of null values for each numerical column\nfor col in number_columns_train:\n    print(f\"{col} has {train_df[col].isnull().mean() *100} Missing Values\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:40.230660Z","iopub.execute_input":"2024-12-10T18:50:40.231015Z","iopub.status.idle":"2024-12-10T18:50:40.631593Z","shell.execute_reply.started":"2024-12-10T18:50:40.230983Z","shell.execute_reply":"2024-12-10T18:50:40.630667Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Fill missing values in numeric columns of the training set\nfor col in number_columns_train:\n    train_df[col].fillna(train_df[col].median(), inplace=True)\n\n# Fill missing values in numeric columns of the test set\nfor col in number_columns_test:\n    test_df[col].fillna(test_df[col].median(), inplace=True)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:40.632692Z","iopub.execute_input":"2024-12-10T18:50:40.632962Z","iopub.status.idle":"2024-12-10T18:50:41.888749Z","shell.execute_reply.started":"2024-12-10T18:50:40.632935Z","shell.execute_reply":"2024-12-10T18:50:41.887736Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in train_df.columns:  # Iterate over column names\n    print(f\"{col}: {train_df[col].dtype}\")  # Access the dtype of the column","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:41.889837Z","iopub.execute_input":"2024-12-10T18:50:41.890103Z","iopub.status.idle":"2024-12-10T18:50:41.902736Z","shell.execute_reply.started":"2024-12-10T18:50:41.890077Z","shell.execute_reply":"2024-12-10T18:50:41.901986Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in train_df:\n    print(f\"{col} has {train_df[col].isnull().mean()*100} missing values\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:41.903599Z","iopub.execute_input":"2024-12-10T18:50:41.903835Z","iopub.status.idle":"2024-12-10T18:50:42.589421Z","shell.execute_reply.started":"2024-12-10T18:50:41.903811Z","shell.execute_reply":"2024-12-10T18:50:42.588579Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(12,8))\nsns.histplot(data = train_df, x = \"bg+1:00\",kde=True)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:42.590413Z","iopub.execute_input":"2024-12-10T18:50:42.590665Z","iopub.status.idle":"2024-12-10T18:50:43.679532Z","shell.execute_reply.started":"2024-12-10T18:50:42.590640Z","shell.execute_reply":"2024-12-10T18:50:43.678794Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\n\n# Apply LabelEncoder only to object (categorical) columns\nfor col in train_df.columns:\n    if train_df[col].dtype == 'object':  # Check if the column is categorical\n        label = LabelEncoder()\n        train_df[col] = label.fit_transform(train_df[col])\n        # print(col.info())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:43.680524Z","iopub.execute_input":"2024-12-10T18:50:43.680813Z","iopub.status.idle":"2024-12-10T18:50:46.093564Z","shell.execute_reply.started":"2024-12-10T18:50:43.680786Z","shell.execute_reply":"2024-12-10T18:50:46.092725Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# LabelEncoder","metadata":{}},{"cell_type":"code","source":"# Apply LabelEncoder only to object (categorical) columns\nfor col in test_df.columns:\n    if test_df[col].dtype == 'object':  # Check if the column is categorical\n        label = LabelEncoder()\n        test_df[col] = label.fit_transform(test_df[col])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:46.094645Z","iopub.execute_input":"2024-12-10T18:50:46.094950Z","iopub.status.idle":"2024-12-10T18:50:46.186410Z","shell.execute_reply.started":"2024-12-10T18:50:46.094922Z","shell.execute_reply":"2024-12-10T18:50:46.185586Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in X.columns:  # Iterate over column names\n    print(f\"{col}: {X[col].dtype}\")  # Access the dtype of the column","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:46.426440Z","iopub.execute_input":"2024-12-10T18:50:46.426967Z","iopub.status.idle":"2024-12-10T18:50:46.457398Z","shell.execute_reply.started":"2024-12-10T18:50:46.426929Z","shell.execute_reply":"2024-12-10T18:50:46.456616Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pip install xgboost","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:47.187601Z","iopub.execute_input":"2024-12-10T18:50:47.187933Z","iopub.status.idle":"2024-12-10T18:50:57.338909Z","shell.execute_reply.started":"2024-12-10T18:50:47.187901Z","shell.execute_reply":"2024-12-10T18:50:57.337973Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Train the model","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport xgboost as xgb\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\n\n# Assuming train_df is already loaded as a DataFrame\nX = train_df.drop(\"bg+1:00\", axis=1)  # Features\ny = train_df[\"bg+1:00\"]              # Target\n\n# Splitting the dataset into training and testing sets\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=47)\n\n# Initializing the XGBoost regressor\nxgb_model = xgb.XGBRegressor(\n    objective='reg:squarederror',  # Regression problem\n    n_estimators=150,              # Number of trees\n    learning_rate=0.1,             # Learning rate\n    max_depth=20,                   # Maximum tree depth\n    random_state=47                # Seed for reproducibility\n)\n\n# XGBoost is successfully imported!\n# Best Parameters:\n# n_estimators: 150\n# learning_rate: 0.1\n# max_depth: 20\n# Best R-squared (R²): 0.7309\n\n# Training the model\nxgb_model.fit(X_train, y_train)\n\n# Making predictions\ny_pred = xgb_model.predict(X_test)\n\n# Evaluating the model\nmse = mean_squared_error(y_test, y_pred)\nrmse = mse ** 0.5\n\nprint(f\"Mean Squared Error: {mse:.4f}\")\nprint(f\"Root Mean Squared Error: {rmse:.4f}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:50:57.340264Z","iopub.execute_input":"2024-12-10T18:50:57.340586Z","iopub.status.idle":"2024-12-10T18:57:25.257175Z","shell.execute_reply.started":"2024-12-10T18:50:57.340556Z","shell.execute_reply":"2024-12-10T18:57:25.255967Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.metrics import mean_absolute_error, r2_score\n\n# Making predictions\ny_pred = xgb_model.predict(X_test)\n\n# Evaluating the model\nmse = mean_squared_error(y_test, y_pred)\nrmse = mse ** 0.5\nmae = mean_absolute_error(y_test, y_pred)\nr2 = r2_score(y_test, y_pred)\n\n# Printing evaluation metrics\nprint(f\"Mean Squared Error (MSE): {mse:.4f}\")\nprint(f\"Root Mean Squared Error (RMSE): {rmse:.4f}\")\nprint(f\"Mean Absolute Error (MAE): {mae:.4f}\")\nprint(f\"R-squared (R²): {r2:.4f}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:57:25.258260Z","iopub.execute_input":"2024-12-10T18:57:25.258577Z","iopub.status.idle":"2024-12-10T18:57:25.395477Z","shell.execute_reply.started":"2024-12-10T18:57:25.258539Z","shell.execute_reply":"2024-12-10T18:57:25.393630Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score\n# import xgboost \n# import xgboost as xgb\n# print(\"XGBoost is successfully imported!\")\n\n\n# # Define ranges for hyperparameters\n# n_estimators_range = [50, 100, 150]\n# learning_rate_range = [0.01, 0.1, 0.2]\n# max_depth_range = [5, 10, 20]\n\n# best_params = {}\n# best_r2 = float('-inf')  # Initialize with a very low value\n\n# # Loop through all combinations of hyperparameters\n# for n_estimators in n_estimators_range:\n#     for learning_rate in learning_rate_range:\n#         for max_depth in max_depth_range:\n#             # Train the model with current hyperparameters\n#             xgb_model = xgb.XGBRegressor(\n#                 objective='reg:squarederror',\n#                 n_estimators=n_estimators,\n#                 learning_rate=learning_rate,\n#                 max_depth=max_depth,\n#                 random_state=45\n#             )\n#             xgb_model.fit(x_train, y_train)\n\n#             # Evaluate on the test set\n#             y_pred = xgb_model.predict(x_test)\n#             r2 = r2_score(y_test, y_pred)\n\n#             # Update best parameters if current model is better\n#             if r2 > best_r2:\n#                 best_r2 = r2\n#                 best_params = {\n#                     'n_estimators': n_estimators,\n#                     'learning_rate': learning_rate,\n#                     'max_depth': max_depth\n#                 }\n\n# # Print the best parameters and corresponding R² score\n# print(\"Best Parameters:\")\n# print(f\"n_estimators: {best_params['n_estimators']}\")\n# print(f\"learning_rate: {best_params['learning_rate']}\")\n# print(f\"max_depth: {best_params['max_depth']}\")\n# print(f\"Best R-squared (R²): {best_r2:.4f}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T18:57:25.779464Z","iopub.execute_input":"2024-12-10T18:57:25.779759Z","iopub.status.idle":"2024-12-10T18:57:25.785803Z","shell.execute_reply.started":"2024-12-10T18:57:25.779731Z","shell.execute_reply":"2024-12-10T18:57:25.785126Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in test_df.select_dtypes(include=['object']).columns:\n    test_df[col] = test_df[col].astype('category')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:17:49.681356Z","iopub.execute_input":"2024-12-10T19:17:49.681704Z","iopub.status.idle":"2024-12-10T19:17:49.743628Z","shell.execute_reply.started":"2024-12-10T19:17:49.681663Z","shell.execute_reply":"2024-12-10T19:17:49.742820Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df['hour'] = pd.to_datetime(test_df['time']).dt.hour\ntest_df['minute'] = pd.to_datetime(test_df['time']).dt.minute\ntest_df = test_df.drop(columns=['time'])  # Drop the original time column","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:18:03.886044Z","iopub.execute_input":"2024-12-10T19:18:03.886377Z","iopub.status.idle":"2024-12-10T19:18:03.921194Z","shell.execute_reply.started":"2024-12-10T19:18:03.886349Z","shell.execute_reply":"2024-12-10T19:18:03.920351Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categorical_columns = test_df.select_dtypes(include=['category']).columns\nnon_categorical_columns = test_df.select_dtypes(exclude=['category']).columns\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:20:21.616404Z","iopub.execute_input":"2024-12-10T19:20:21.616808Z","iopub.status.idle":"2024-12-10T19:20:21.625474Z","shell.execute_reply.started":"2024-12-10T19:20:21.616778Z","shell.execute_reply":"2024-12-10T19:20:21.624738Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df[non_categorical_columns] = test_df[non_categorical_columns].fillna(0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:20:32.166400Z","iopub.execute_input":"2024-12-10T19:20:32.166757Z","iopub.status.idle":"2024-12-10T19:20:32.239092Z","shell.execute_reply.started":"2024-12-10T19:20:32.166728Z","shell.execute_reply":"2024-12-10T19:20:32.238348Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in categorical_columns:\n    test_df[col] = test_df[col].cat.add_categories([0])  # Add 0 as a new category\n    test_df[col] = test_df[col].fillna(0)  # Fill missing values with 0","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:20:48.514214Z","iopub.execute_input":"2024-12-10T19:20:48.514903Z","iopub.status.idle":"2024-12-10T19:20:48.558150Z","shell.execute_reply.started":"2024-12-10T19:20:48.514867Z","shell.execute_reply":"2024-12-10T19:20:48.557488Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in categorical_columns:\n    most_frequent = test_df[col].mode()[0]\n    test_df[col] = test_df[col].fillna(most_frequent)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:21:00.059892Z","iopub.execute_input":"2024-12-10T19:21:00.060209Z","iopub.status.idle":"2024-12-10T19:21:00.091537Z","shell.execute_reply.started":"2024-12-10T19:21:00.060182Z","shell.execute_reply":"2024-12-10T19:21:00.090881Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(test_df.info())  # Verify data types and missing values\nprint(test_df.isnull().sum())  # Ensure all missing values are handled\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:21:12.746727Z","iopub.execute_input":"2024-12-10T19:21:12.747585Z","iopub.status.idle":"2024-12-10T19:21:12.796789Z","shell.execute_reply.started":"2024-12-10T19:21:12.747548Z","shell.execute_reply":"2024-12-10T19:21:12.795824Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_predictions = xgb_model.predict(test_df)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:23:01.053514Z","iopub.execute_input":"2024-12-10T19:23:01.054397Z","iopub.status.idle":"2024-12-10T19:23:01.188543Z","shell.execute_reply.started":"2024-12-10T19:23:01.054364Z","shell.execute_reply":"2024-12-10T19:23:01.187369Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_predictions = xgb_model.predict(test_df)\n\nsubmission = pd.DataFrame({\n    \"Id\": test_df[\"id\"],  # Ensure this matches the ID column in your test dataset\n    \"Target\": test_predictions  # Replace 'Target' with the required target column name\n})\nsubmission.to_csv(\"submission.csv\", index=False)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-10T19:23:02.235036Z","iopub.execute_input":"2024-12-10T19:23:02.235401Z","iopub.status.idle":"2024-12-10T19:23:02.356062Z","shell.execute_reply.started":"2024-12-10T19:23:02.235370Z","shell.execute_reply":"2024-12-10T19:23:02.354852Z"}},"outputs":[],"execution_count":null}]}