{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":82253,"databundleVersionId":8965849,"sourceType":"competition"}],"dockerImageVersionId":30732,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"colab":{"name":"winner_notebook","provenance":[]}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"\n# IMPORTANT: RUN THIS CELL IN ORDER TO IMPORT YOUR KAGGLE DATA SOURCES\n# TO THE CORRECT LOCATION (/kaggle/input) IN YOUR NOTEBOOK,\n# THEN FEEL FREE TO DELETE THIS CELL.\n# NOTE: THIS NOTEBOOK ENVIRONMENT DIFFERS FROM KAGGLE'S PYTHON\n# ENVIRONMENT SO THERE MAY BE MISSING LIBRARIES USED BY YOUR\n# NOTEBOOK.\n\nimport os\nimport sys\nfrom tempfile import NamedTemporaryFile\nfrom urllib.request import urlopen\nfrom urllib.parse import unquote, urlparse\nfrom urllib.error import HTTPError\nfrom zipfile import ZipFile\nimport tarfile\nimport shutil\n\nCHUNK_SIZE = 40960\nDATA_SOURCE_MAPPING = 'f1nalyze-datathon-ieeecsmuj:https%3A%2F%2Fstorage.googleapis.com%2Fkaggle-competitions-data%2Fkaggle-v2%2F82253%2F8965849%2Fbundle%2Farchive.zip%3FX-Goog-Algorithm%3DGOOG4-RSA-SHA256%26X-Goog-Credential%3Dgcp-kaggle-com%2540kaggle-161607.iam.gserviceaccount.com%252F20240628%252Fauto%252Fstorage%252Fgoog4_request%26X-Goog-Date%3D20240628T192611Z%26X-Goog-Expires%3D259200%26X-Goog-SignedHeaders%3Dhost%26X-Goog-Signature%3D74ac1557313a5c6d7867c1becd6dfbf758ad957714e79e0ee6f06c7e7bc340c2dbc5b5286b0305b3f6d1ebbd9e5d0a0b9d6560fd799496d4efd7bcf9f66c9a16ddc42b0997d05eab16f9856815bf7accd4138422c2d05e99bbaaf46f75a345c53d24618bd2a6df97c5489bd1e2776f5a417486b2d5e7dad32537ab6be9d40d92e07879656f522f3faca2bf728e6ecd8f0ccb469e3478de6580fe33852745bd39e74e8aeb438567453112c318066224f30a862f4acc06517306208ba4879a67d017b847699fb9eb674d92bb8a189d19ff989256faeabc8307c610483e6c5f8ed2ec084b185233b913d325eb69663d3ee007e18934c48f5c2a8861fd687ff7988b'\n\nKAGGLE_INPUT_PATH='/kaggle/input'\nKAGGLE_WORKING_PATH='/kaggle/working'\nKAGGLE_SYMLINK='kaggle'\n\n!umount /kaggle/input/ 2> /dev/null\nshutil.rmtree('/kaggle/input', ignore_errors=True)\nos.makedirs(KAGGLE_INPUT_PATH, 0o777, exist_ok=True)\nos.makedirs(KAGGLE_WORKING_PATH, 0o777, exist_ok=True)\n\ntry:\n  os.symlink(KAGGLE_INPUT_PATH, os.path.join(\"..\", 'input'), target_is_directory=True)\nexcept FileExistsError:\n  pass\ntry:\n  os.symlink(KAGGLE_WORKING_PATH, os.path.join(\"..\", 'working'), target_is_directory=True)\nexcept FileExistsError:\n  pass\n\nfor data_source_mapping in DATA_SOURCE_MAPPING.split(','):\n    directory, download_url_encoded = data_source_mapping.split(':')\n    download_url = unquote(download_url_encoded)\n    filename = urlparse(download_url).path\n    destination_path = os.path.join(KAGGLE_INPUT_PATH, directory)\n    try:\n        with urlopen(download_url) as fileres, NamedTemporaryFile() as tfile:\n            total_length = fileres.headers['content-length']\n            print(f'Downloading {directory}, {total_length} bytes compressed')\n            dl = 0\n            data = fileres.read(CHUNK_SIZE)\n            while len(data) > 0:\n                dl += len(data)\n                tfile.write(data)\n                done = int(50 * dl / int(total_length))\n                sys.stdout.write(f\"\\r[{'=' * done}{' ' * (50-done)}] {dl} bytes downloaded\")\n                sys.stdout.flush()\n                data = fileres.read(CHUNK_SIZE)\n            if filename.endswith('.zip'):\n              with ZipFile(tfile) as zfile:\n                zfile.extractall(destination_path)\n            else:\n              with tarfile.open(tfile.name) as tarfile:\n                tarfile.extractall(destination_path)\n            print(f'\\nDownloaded and uncompressed: {directory}')\n    except HTTPError as e:\n        print(f'Failed to load (likely expired) {download_url} to path {destination_path}')\n        continue\n    except OSError as e:\n        print(f'Failed to load {download_url} to path {destination_path}')\n        continue\n\nprint('Data source import complete.')\n","metadata":{"id":"DEj54GhCT_1Y","outputId":"37e30730-0d45-4a14-8f9b-b4d472259b10","execution":{"iopub.status.busy":"2024-06-29T04:49:22.739094Z","iopub.execute_input":"2024-06-29T04:49:22.739612Z","iopub.status.idle":"2024-06-29T04:49:25.998149Z","shell.execute_reply.started":"2024-06-29T04:49:22.739571Z","shell.execute_reply":"2024-06-29T04:49:25.996821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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 numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\"\n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","id":"igrOoWYnT_1f","outputId":"097eb77b-2887-4f89-c3ca-99bf3ed1c878","execution":{"iopub.status.busy":"2024-06-29T04:49:26.001075Z","iopub.execute_input":"2024-06-29T04:49:26.001579Z","iopub.status.idle":"2024-06-29T04:49:27.295081Z","shell.execute_reply.started":"2024-06-29T04:49:26.001530Z","shell.execute_reply":"2024-06-29T04:49:27.293947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\n# Replace 'filename.csv' with the actual CSV file name in the dataset\ntrain = '/kaggle/input/f1nalyze-datathon-ieeecsmuj/train.csv'\ntrain_ = pd.read_csv(train)\n\n# Display the first few rows of the DataFrame\ntrain_.head()\n","metadata":{"id":"mx8Y1aONT_1g","outputId":"10ef974f-b3df-4363-f238-d0ea8b75f5d0","execution":{"iopub.status.busy":"2024-06-29T04:49:27.296676Z","iopub.execute_input":"2024-06-29T04:49:27.297208Z","iopub.status.idle":"2024-06-29T04:50:05.825055Z","shell.execute_reply.started":"2024-06-29T04:49:27.297173Z","shell.execute_reply":"2024-06-29T04:50:05.823731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = '/kaggle/input/f1nalyze-datathon-ieeecsmuj/test.csv'\ntest_ = pd.read_csv(test)\n\n# Display the first few rows of the DataFrame\ntest_.head()\n","metadata":{"id":"iWGrxcMXT_1i","outputId":"0b0c17aa-c67e-4793-9ecf-79e6ce456965","execution":{"iopub.status.busy":"2024-06-29T04:50:05.827194Z","iopub.execute_input":"2024-06-29T04:50:05.827543Z","iopub.status.idle":"2024-06-29T04:50:10.367974Z","shell.execute_reply.started":"2024-06-29T04:50:05.827513Z","shell.execute_reply":"2024-06-29T04:50:10.366887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"validation = '/kaggle/input/f1nalyze-datathon-ieeecsmuj/test.csv'\nvalidation_ = pd.read_csv(validation)\n\n# Display the first few rows of the DataFrame\nvalidation_.head()","metadata":{"id":"nmHQ7kQyT_1j","outputId":"5748e5e4-80c3-49f8-e00e-5278a35bb77c","execution":{"iopub.status.busy":"2024-06-29T04:50:10.369184Z","iopub.execute_input":"2024-06-29T04:50:10.369547Z","iopub.status.idle":"2024-06-29T04:50:13.836433Z","shell.execute_reply.started":"2024-06-29T04:50:10.369517Z","shell.execute_reply":"2024-06-29T04:50:13.835067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" **EDA**","metadata":{}},{"cell_type":"code","source":"columns_to_drop = [\n    'resultId', 'racerId', 'positionText_x', 'time_x', 'timetaken_in_millisec',\n    'fastestLapTime', 'max_speed', 'statusId', 'grand_prix', 'date', 'time_y',\n    'url_x', 'fp1_date', 'fp1_time', 'fp2_date', 'fp2_time', 'fp3_date','number', 'grid',\n    'fp3_time', 'quali_date', 'quali_time', 'sprint_date', 'sprint_time',\n    'driverRef', 'driver_num', 'driver_code', 'forename', 'surname', 'dob','fastestLap', 'rank', 'year', 'round',\n    'nationality', 'url_y', 'constructorRef', 'company', 'nationality_y', 'url',\n    'status',  'positionText_y','position_x',\n]\n","metadata":{"id":"P5RLb4s9T_1j","execution":{"iopub.status.busy":"2024-06-29T05:24:37.085215Z","iopub.execute_input":"2024-06-29T05:24:37.085783Z","iopub.status.idle":"2024-06-29T05:24:37.094355Z","shell.execute_reply.started":"2024-06-29T05:24:37.085726Z","shell.execute_reply":"2024-06-29T05:24:37.093155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = train_.drop(columns = columns_to_drop)","metadata":{"id":"37uRQn1OT_1k","execution":{"iopub.status.busy":"2024-06-29T05:24:42.625335Z","iopub.execute_input":"2024-06-29T05:24:42.625782Z","iopub.status.idle":"2024-06-29T05:24:42.843816Z","shell.execute_reply.started":"2024-06-29T05:24:42.625746Z","shell.execute_reply":"2024-06-29T05:24:42.842552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(df.columns)","metadata":{"id":"GTUU720HT_1l","outputId":"33a248d4-6916-470d-eb21-a900416903a5","execution":{"iopub.status.busy":"2024-06-29T05:24:48.905184Z","iopub.execute_input":"2024-06-29T05:24:48.905593Z","iopub.status.idle":"2024-06-29T05:24:48.912343Z","shell.execute_reply.started":"2024-06-29T05:24:48.905562Z","shell.execute_reply":"2024-06-29T05:24:48.910948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"CREATING NEW FEATURE DRIVER CONFIDENCE","metadata":{}},{"cell_type":"code","source":"\n\n# Assuming df is your DataFrame and it contains the columns 'driver' and 'dnf_reason'\ndnf_reasons = [3, 4, 20, 29, 31, 41, 68, 73, 81, 97, 82, 104, 107, 130, 137]\n\n# Create new feature for DNF indicators\ndf['driver_dnf'] = df['laps'].apply(lambda x: 1 if x in dnf_reasons else 0)\n\n# Group by 'driver' and sum the 'driver_dnf' column to get total DNFs per driver\ndnf_by_driver = df.groupby('driverId')['driver_dnf'].sum()\n\n# Count the total races entered per driver\ndriver_race_entered = df.groupby('driverId')['driver_dnf'].count()\n\n# Calculate the DNF ratio\ndriver_dnf_ratio = dnf_by_driver / driver_race_entered\n\n# Calculate driver confidence\ndriver_confidence = 1 - driver_dnf_ratio\n\n# Convert driver_confidence Series to DataFrame and merge it back to the original DataFrame if needed\ndriver_confidence_df = driver_confidence.reset_index()\ndf = df.merge(driver_confidence_df, on='driverId', how='left', suffixes=('', '_confidence'))\n\n# Rename the confidence column appropriately\ndf.rename(columns={'driver_dnf_confidence': 'driver_confidence'}, inplace=True)\n\n# Display the updated DataFrame with driver confidence\nprint(df.head())\n","metadata":{"id":"lOM1ubpFT_1o","outputId":"8de01ef7-4604-4ebe-aba9-0addd9b96a3e","execution":{"iopub.status.busy":"2024-06-29T04:50:14.054934Z","iopub.execute_input":"2024-06-29T04:50:14.055350Z","iopub.status.idle":"2024-06-29T04:50:16.361427Z","shell.execute_reply.started":"2024-06-29T04:50:14.055313Z","shell.execute_reply":"2024-06-29T04:50:16.360230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numerical_features = ['points_y ', ' wins', 'driver_confidence ']\ncatergorical_features =['driverId','constructorId','circuitId']\n","metadata":{"id":"u9PTwdGXT_1p","execution":{"iopub.status.busy":"2024-06-29T04:50:16.365771Z","iopub.execute_input":"2024-06-29T04:50:16.366145Z","iopub.status.idle":"2024-06-29T04:50:16.371435Z","shell.execute_reply.started":"2024-06-29T04:50:16.366114Z","shell.execute_reply":"2024-06-29T04:50:16.370302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = df.replace(r'\\\\N', pd.NA, regex=True)\ndf = df.dropna()\n\n# Convert columns to appropriate numeric types\ndf['laps'] = pd.to_numeric(df['laps'], errors='coerce')\ndf['points'] = pd.to_numeric(df['points'], errors='coerce')\n\n# Drop rows with NaN values after type conversion\n#df = df.dropna()\ndf = df.dropna()","metadata":{"id":"SXq9ESgmT_1p","outputId":"c8139d79-a665-46f7-af27-e58b815ef519","execution":{"iopub.status.busy":"2024-06-29T04:50:16.373037Z","iopub.execute_input":"2024-06-29T04:50:16.373570Z","iopub.status.idle":"2024-06-29T04:50:22.131195Z","shell.execute_reply.started":"2024-06-29T04:50:16.373526Z","shell.execute_reply":"2024-06-29T04:50:22.130129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMPLEMENTING LIGHTGBM ABD GBR","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn.model_selection import train_test_split, GridSearchCV","metadata":{"id":"D5zZ5TvqT_1q","execution":{"iopub.status.busy":"2024-06-29T04:50:22.133169Z","iopub.execute_input":"2024-06-29T04:50:22.133623Z","iopub.status.idle":"2024-06-29T04:50:23.119278Z","shell.execute_reply.started":"2024-06-29T04:50:22.133581Z","shell.execute_reply":"2024-06-29T04:50:23.118034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"HEAVY GBR","metadata":{}},{"cell_type":"code","source":"X_train = df.drop(['position'], axis=1)  # Features\ny_train = df['position']  # Target\n\n# Split training data into train and internal validation sets\nX_train, X_val_internal, y_train, y_val_internal = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n\n# Initialize and train Gradient Boosting Regressor\nparams = {\n    'n_estimators': [100, 200, 300],  # Number of boosting stages\n    'max_depth': [3, 5, 7],  # Depth of each tree\n    'learning_rate': [0.1, 0.05, 0.01],  # Step size shrinkage\n    'loss': ['ls', 'lad', 'huber']  # Loss function to optimize\n}\n\ngbr = GradientBoostingRegressor(random_state=42)\ngrid_search = GridSearchCV(gbr, param_grid=params, cv=5, scoring='neg_root_mean_squared_error')\ngrid_search.fit(X_train, y_train)\n\nbest_model = grid_search.best_estimator_ implement lightgbm","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\n\n# Assuming train_df is your DataFrame containing both numerical and categorical columns\nnumerical_features = ['points_y', 'wins', 'driver_confidence']\ncategorical_features = ['driverId', 'constructorId', 'circuitId']\n\n# Select only the numerical columns for scaling\nnumerical_df = df[numerical_features]\n\n# Initialize the StandardScaler\nscaler = StandardScaler()\n\n# Fit and transform the numerical data\ndf[numerical_features] = scaler.fit_transform(numerical_df)","metadata":{"id":"FdHJA1jZT_1r","execution":{"iopub.status.busy":"2024-06-29T04:50:23.121026Z","iopub.execute_input":"2024-06-29T04:50:23.121509Z","iopub.status.idle":"2024-06-29T04:50:23.167477Z","shell.execute_reply.started":"2024-06-29T04:50:23.121466Z","shell.execute_reply":"2024-06-29T04:50:23.166232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install lightgbm\n","metadata":{"execution":{"iopub.status.busy":"2024-06-29T05:19:04.598097Z","iopub.execute_input":"2024-06-29T05:19:04.598838Z","iopub.status.idle":"2024-06-29T05:19:18.879688Z","shell.execute_reply.started":"2024-06-29T05:19:04.598788Z","shell.execute_reply":"2024-06-29T05:19:18.878034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import lightgbm as lgb\nfrom sklearn.model_selection import train_test_split, GridSearchCV\nfrom sklearn.metrics import mean_squared_error\n","metadata":{"execution":{"iopub.status.busy":"2024-06-29T05:19:41.832019Z","iopub.execute_input":"2024-06-29T05:19:41.832492Z","iopub.status.idle":"2024-06-29T05:19:43.053472Z","shell.execute_reply.started":"2024-06-29T05:19:41.832436Z","shell.execute_reply":"2024-06-29T05:19:43.052283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import train_test_split, GridSearchCV\nfrom sklearn.metrics import mean_squared_error\nimport lightgbm as lgb\n\n# Prepare data\nX_train = df.drop(['position'], axis=1)  # Features\ny_train = df['position']  # Target\n\n# Split training data into train and internal validation sets\nX_train, X_val_internal, y_train, y_val_internal = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n\n# Define parameter grid for LightGBM\nparams = {\n    'n_estimators': [100, 200, 300],  # Number of boosting stages\n    'max_depth': [3, 5, 7],  # Maximum depth of each tree\n    'learning_rate': [0.1, 0.05, 0.01],  # Learning rate\n    'num_leaves': [2**3, 2**5, 2**7],  # Number of leaves in full tree, matching 2^max_depth\n    'boosting_type': ['gbdt'],  # Boosting type (default is 'gbdt')\n    'objective': ['regression'],  # Objective function (default is 'regression')\n    'metric': ['rmse'],  # Evaluation metric (default is 'rmse')\n    'force_col_wise': [True]  # Force column-wise multi-threading\n}\n\n# Initialize and perform grid search with verbose output\nlgb_reg = lgb.LGBMRegressor(random_state=42)\ngrid_search = GridSearchCV(lgb_reg, param_grid=params, cv=5, scoring='neg_root_mean_squared_error', verbose=2)\ngrid_search.fit(X_train, y_train)\n\n# Get the best model\nbest_model = grid_search.best_estimator_\n\n# Evaluate the model\ny_val_pred = best_model.predict(X_val_internal)\nrmse = mean_squared_error(y_val_internal, y_val_pred, squared=False)\nprint(f'Best Parameters: {grid_search.best_params_}')\nprint(f'Validation RMSE: {rmse}')\n\n","metadata":{"execution":{"iopub.status.busy":"2024-06-29T06:00:56.173352Z","iopub.execute_input":"2024-06-29T06:00:56.173786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"LIGHT WEIGHT LGB ","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn.model_selection import train_test_split, GridSearchCV\nfrom sklearn.metrics import mean_squared_error\nimport lightgbm as lgb\n\n# Prepare data\nX_train = df.drop(['position'], axis=1)  # Features\ny_train = df['position']  # Target\n\n# Split training data into train and internal validation sets\nX_train, X_val_internal, y_train, y_val_internal = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n\n# Define parameter grid for LightGBM with fewer combinations\nparams = {\n    'n_estimators': [100, 200],  # Reduced number of boosting stages\n    'max_depth': [3, 5],  # Reduced maximum depth of each tree\n    'learning_rate': [0.1, 0.05],  # Reduced learning rate options\n    'num_leaves': [31, 50],  # Reduced number of leaves in full tree\n    'boosting_type': ['gbdt'],  # Boosting type (default is 'gbdt')\n    'objective': ['regression'],  # Objective function (default is 'regression')\n    'metric': ['rmse'],  # Evaluation metric (default is 'rmse')\n    'force_col_wise': [True]  # Force column-wise multi-threading\n}\n\n# Initialize and perform grid search with verbose output\nlgb_reg = lgb.LGBMRegressor(random_state=42)\ngrid_search = GridSearchCV(lgb_reg, param_grid=params, cv=5, scoring='neg_root_mean_squared_error', verbose=2)\ngrid_search.fit(X_train, y_train)\n\n# Get the best model\nbest_model = grid_search.best_estimator_\n\n# Evaluate the model\ny_val_pred = best_model.predict(X_val_internal)\nrmse = mean_squared_error(y_val_internal, y_val_pred, squared=False)\nprint(f'Best Parameters: {grid_search.best_params_}')\nprint(f'Validation RMSE: {rmse}')\n","metadata":{"execution":{"iopub.status.busy":"2024-06-29T05:48:15.530161Z","iopub.execute_input":"2024-06-29T05:48:15.530591Z","iopub.status.idle":"2024-06-29T05:59:29.027068Z","shell.execute_reply.started":"2024-06-29T05:48:15.530554Z","shell.execute_reply":"2024-06-29T05:59:29.025312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\nimport numpy as np\n\n# Predict on the internal validation set\ny_pred_internal = best_model.predict(X_val_internal)\n\n# Calculate RMSE (Root Mean Squared Error)\nrmse_internal = np.sqrt(mean_squared_error(y_val_internal, y_pred_internal))\nprint(f\"Internal Validation RMSE: {rmse_internal}\")","metadata":{"id":"jsvlsloCUa4d","execution":{"iopub.status.busy":"2024-06-29T05:47:54.604209Z","iopub.status.idle":"2024-06-29T05:47:54.605057Z","shell.execute_reply.started":"2024-06-29T05:47:54.604775Z","shell.execute_reply":"2024-06-29T05:47:54.604801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Prepare output in CSV format\noutput_df = pd.DataFrame({\n    'position': test_predictions,\n        'driver standing id': test_df['driver standing id']  # Assuming this column exists in test_df\n        })","metadata":{"id":"j8eCy_pXUWS_","execution":{"iopub.status.busy":"2024-06-29T05:11:50.475487Z","iopub.status.idle":"2024-06-29T05:11:50.476019Z","shell.execute_reply.started":"2024-06-29T05:11:50.475754Z","shell.execute_reply":"2024-06-29T05:11:50.475777Z"},"trusted":true},"execution_count":null,"outputs":[]}]}