{"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":"gpu","dataSources":[{"sourceId":104857,"databundleVersionId":12651513,"sourceType":"competition"}],"dockerImageVersionId":31041,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"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","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:20:58.147288Z","iopub.execute_input":"2025-06-14T07:20:58.147560Z","iopub.status.idle":"2025-06-14T07:21:01.539963Z","shell.execute_reply.started":"2025-06-14T07:20:58.147533Z","shell.execute_reply":"2025-06-14T07:21:01.539047Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# pd.set_option('display.max_rows', None)\npd.set_option('display.max_columns', None)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:21:54.440320Z","iopub.execute_input":"2025-06-14T07:21:54.440894Z","iopub.status.idle":"2025-06-14T07:21:54.444265Z","shell.execute_reply.started":"2025-06-14T07:21:54.440872Z","shell.execute_reply":"2025-06-14T07:21:54.443508Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/burnout-datathon-ieeecsmuj/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:21:54.870357Z","iopub.execute_input":"2025-06-14T07:21:54.870644Z","iopub.status.idle":"2025-06-14T07:22:08.708543Z","shell.execute_reply.started":"2025-06-14T07:21:54.870624Z","shell.execute_reply":"2025-06-14T07:22:08.707978Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:41:07.468610Z","iopub.execute_input":"2025-06-14T05:41:07.468875Z","iopub.status.idle":"2025-06-14T05:41:07.504171Z","shell.execute_reply.started":"2025-06-14T05:41:07.468851Z","shell.execute_reply":"2025-06-14T05:41:07.503560Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:41:07.504938Z","iopub.execute_input":"2025-06-14T05:41:07.505287Z","iopub.status.idle":"2025-06-14T05:41:07.514981Z","shell.execute_reply.started":"2025-06-14T05:41:07.505263Z","shell.execute_reply":"2025-06-14T05:41:07.514508Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.dtypes","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:41:07.516193Z","iopub.execute_input":"2025-06-14T05:41:07.516408Z","iopub.status.idle":"2025-06-14T05:41:07.536429Z","shell.execute_reply.started":"2025-06-14T05:41:07.516387Z","shell.execute_reply":"2025-06-14T05:41:07.535729Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.isnull().sum().sort_values(ascending=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:20:33.465544Z","iopub.execute_input":"2025-06-14T05:20:33.466491Z","iopub.status.idle":"2025-06-14T05:20:34.580921Z","shell.execute_reply.started":"2025-06-14T05:20:33.466458Z","shell.execute_reply":"2025-06-14T05:20:34.580182Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:20:39.789913Z","iopub.execute_input":"2025-06-14T05:20:39.790206Z","iopub.status.idle":"2025-06-14T05:20:41.776345Z","shell.execute_reply.started":"2025-06-14T05:20:39.790186Z","shell.execute_reply":"2025-06-14T05:20:41.775599Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Penalty'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:15:54.838196Z","iopub.execute_input":"2025-06-14T05:15:54.838930Z","iopub.status.idle":"2025-06-14T05:15:54.907624Z","shell.execute_reply.started":"2025-06-14T05:15:54.838910Z","shell.execute_reply":"2025-06-14T05:15:54.906992Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Tire_Compound_Front'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:15:16.050845Z","iopub.execute_input":"2025-06-14T06:15:16.051406Z","iopub.status.idle":"2025-06-14T06:15:16.132178Z","shell.execute_reply.started":"2025-06-14T06:15:16.051385Z","shell.execute_reply":"2025-06-14T06:15:16.131632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Penalty'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:16:00.264695Z","iopub.execute_input":"2025-06-14T05:16:00.264948Z","iopub.status.idle":"2025-06-14T05:16:00.382940Z","shell.execute_reply.started":"2025-06-14T05:16:00.264929Z","shell.execute_reply":"2025-06-14T05:16:00.382063Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[df['Penalty'] == 'DNF']['Lap_Time_Seconds'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:16:18.781641Z","iopub.execute_input":"2025-06-14T05:16:18.781897Z","iopub.status.idle":"2025-06-14T05:16:19.017782Z","shell.execute_reply.started":"2025-06-14T05:16:18.781878Z","shell.execute_reply":"2025-06-14T05:16:19.017119Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['category_x'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:34:26.690997Z","iopub.execute_input":"2025-06-14T05:34:26.691651Z","iopub.status.idle":"2025-06-14T05:34:26.796388Z","shell.execute_reply.started":"2025-06-14T05:34:26.691620Z","shell.execute_reply":"2025-06-14T05:34:26.795751Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Session'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:22:38.404191Z","iopub.execute_input":"2025-06-14T06:22:38.404456Z","iopub.status.idle":"2025-06-14T06:22:38.495011Z","shell.execute_reply.started":"2025-06-14T06:22:38.404436Z","shell.execute_reply":"2025-06-14T06:22:38.494452Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['circuit_name'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:16:35.932848Z","iopub.execute_input":"2025-06-14T05:16:35.933440Z","iopub.status.idle":"2025-06-14T05:16:36.036579Z","shell.execute_reply.started":"2025-06-14T05:16:35.933419Z","shell.execute_reply":"2025-06-14T05:16:36.036016Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['rider_name'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:11:30.284246Z","iopub.execute_input":"2025-06-14T05:11:30.284542Z","iopub.status.idle":"2025-06-14T05:11:30.402607Z","shell.execute_reply.started":"2025-06-14T05:11:30.284520Z","shell.execute_reply":"2025-06-14T05:11:30.401960Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[(df['rider_name'] == 'Ogura, Ai')]['circuit_name'].unique()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:00:17.441171Z","iopub.execute_input":"2025-06-14T05:00:17.441729Z","iopub.status.idle":"2025-06-14T05:00:17.575200Z","shell.execute_reply.started":"2025-06-14T05:00:17.441705Z","shell.execute_reply":"2025-06-14T05:00:17.574574Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"silverstone2012gp = df[(df['circuit_name'] == 'Silverstone') & (df['category_x'] == 'MotoGP') & (df['year_x'] == 2012) & (df['Session'] == 'Race')]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:07:06.697808Z","iopub.execute_input":"2025-06-14T06:07:06.698179Z","iopub.status.idle":"2025-06-14T06:07:07.124068Z","shell.execute_reply.started":"2025-06-14T06:07:06.698144Z","shell.execute_reply":"2025-06-14T06:07:07.123296Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"silverstone2012gp","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:07:07.157519Z","iopub.execute_input":"2025-06-14T06:07:07.157727Z","iopub.status.idle":"2025-06-14T06:07:07.181704Z","shell.execute_reply.started":"2025-06-14T06:07:07.157712Z","shell.execute_reply":"2025-06-14T06:07:07.181011Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df[(df['circuit_name'] == 'Silverstone') & (df['rider_name'] == 'North, Alan') & (df['category_x'] == 'MotoGP')]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T05:03:41.685862Z","iopub.execute_input":"2025-06-14T05:03:41.686429Z","iopub.status.idle":"2025-06-14T05:03:42.072389Z","shell.execute_reply.started":"2025-06-14T05:03:41.686408Z","shell.execute_reply":"2025-06-14T05:03:42.071503Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tire_factors = {\n    'Soft': 0.98,\n    'Medium': 1.00,\n    'Hard': 1.02\n}\ntrack_factors = {\n    'Dry': 1.00,\n    'Wet': 1.05\n}\ntime_loss_per_corner = 0.5\nride_through_time = 20\n\ndf['Penalty_Seconds'] = df['Penalty'].map({\n    '+3s': 3,\n    '+5s': 5,\n    'Ride Through': ride_through_time,\n    'DNS': np.nan,\n    'DNF': np.nan\n}).fillna(0)\n\ndf['Base_Lap_Time'] = (df['Circuit_Length_km'] * 3600) / df['Avg_Speed_kmh']\ndf['Tire_Compound_Factor'] = df['Tire_Compound_Front'].map(tire_factors).fillna(1.0)\ndf['Track_Condition_Factor'] = df['Track_Condition'].map(track_factors).fillna(1.0)\ndf['Corner_Penalty'] = df['Corners_per_Lap'] * time_loss_per_corner\ndf['Tire_Degradation_Penalty'] = df['Tire_Degradation_Factor_per_Lap'] * df['Laps']\n\ndf['Temperature_Adjustment'] = 1.0\ndf.loc[df['Track_Temperature_Celsius'] < 20, 'Temperature_Adjustment'] = 1.02\ndf.loc[df['Track_Temperature_Celsius'] > 40, 'Temperature_Adjustment'] = 1.01\ndf.loc[df['Humidity_%'] > 80, 'Base_Lap_Time'] += 0.1\n\ndf['Theoretical_Lap_Time'] = (\n    df['Base_Lap_Time'] * \n    df['Tire_Compound_Factor'] * \n    df['Track_Condition_Factor'] * \n    df['Temperature_Adjustment'] + \n    df['Corner_Penalty'] + \n    df['Tire_Degradation_Penalty'] + \n    df['Penalty_Seconds']\n)\n\ndf_valid = df[df['Penalty_Seconds'].notna()]\ndf_valid[['Lap_Time_Seconds', 'Theoretical_Lap_Time']]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:30:00.237766Z","iopub.execute_input":"2025-06-14T06:30:00.238032Z","iopub.status.idle":"2025-06-14T06:30:01.351795Z","shell.execute_reply.started":"2025-06-14T06:30:00.238014Z","shell.execute_reply":"2025-06-14T06:30:01.351199Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_valid[['Lap_Time_Seconds', 'Theoretical_Lap_Time']].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T06:30:09.087450Z","iopub.execute_input":"2025-06-14T06:30:09.087886Z","iopub.status.idle":"2025-06-14T06:30:09.252911Z","shell.execute_reply.started":"2025-06-14T06:30:09.087862Z","shell.execute_reply":"2025-06-14T06:30:09.252231Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install -q tqdm_joblib","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:00:05.353797Z","iopub.execute_input":"2025-06-14T07:00:05.354394Z","iopub.status.idle":"2025-06-14T07:00:09.511065Z","shell.execute_reply.started":"2025-06-14T07:00:05.354372Z","shell.execute_reply":"2025-06-14T07:00:09.510271Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.metrics import mean_absolute_error, r2_score\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import OneHotEncoder\nimport category_encoders as ce\nfrom lightgbm import LGBMRegressor, early_stopping, log_evaluation","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:24:57.741335Z","iopub.execute_input":"2025-06-14T07:24:57.742069Z","iopub.status.idle":"2025-06-14T07:25:01.981610Z","shell.execute_reply.started":"2025-06-14T07:24:57.742045Z","shell.execute_reply":"2025-06-14T07:25:01.980854Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Penalty_Seconds'] = df['Penalty'].map({\n    '+3s': 3,\n    '+5s': 5,\n    'Ride Through': 20,\n    'DNS': np.nan,\n    'DNF': np.nan\n}).fillna(0)\n\ndf = df[df['Penalty_Seconds'].notna()]\n\ndf['Tire_Combo'] = df['Tire_Compound_Front'] + '_' + df['Tire_Compound_Rear']\ndf['Temperature_Diff'] = df['Track_Temperature_Celsius'] - df['Ambient_Temperature_Celsius']\n\ntarget = 'Lap_Time_Seconds'\nfeatures = [\n    'Circuit_Length_km', 'Avg_Speed_kmh', 'Corners_per_Lap',\n    'Tire_Degradation_Factor_per_Lap', 'Pit_Stop_Duration_Seconds',\n    'Ambient_Temperature_Celsius', 'Track_Temperature_Celsius', 'Penalty_Seconds',\n    'Temperature_Diff', 'Track_Condition', 'Tire_Compound_Front',\n    'Tire_Compound_Rear', 'Tire_Combo', 'Session', 'circuit_name'\n]\n\nnumerical_features = [\n    'Circuit_Length_km', 'Avg_Speed_kmh', 'Corners_per_Lap',\n    'Tire_Degradation_Factor_per_Lap', 'Pit_Stop_Duration_Seconds',\n    'Ambient_Temperature_Celsius', 'Track_Temperature_Celsius', 'Penalty_Seconds',\n    'Temperature_Diff'\n]\nlow_cardinality_categorical = [\n    'Track_Condition', 'Tire_Compound_Front', 'Tire_Compound_Rear',\n    'Tire_Combo', 'Session'\n]\nhigh_cardinality_categorical = ['circuit_name']\n\nfor col in numerical_features:\n    df[col] = df[col].astype('float32')\n\nX = df[features]\ny = df[target].astype('float32')\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.1, random_state=42)\n\nnumerical_transformer = Pipeline(steps=[\n    ('imputer', SimpleImputer(strategy='median')),\n    ('scaler', StandardScaler())\n])\n\nlow_cardinality_transformer = Pipeline(steps=[\n    ('imputer', SimpleImputer(strategy='constant', fill_value='Unknown')),\n    ('onehot', OneHotEncoder(handle_unknown='ignore', sparse_output=True))\n])\n\nhigh_cardinality_transformer = Pipeline(steps=[\n    ('imputer', SimpleImputer(strategy='constant', fill_value='Unknown')),\n    ('target', ce.TargetEncoder())\n])\n\npreprocessor = ColumnTransformer(\n    transformers=[\n        ('num', numerical_transformer, numerical_features),\n        ('low_cat', low_cardinality_transformer, low_cardinality_categorical),\n        ('high_cat', high_cardinality_transformer, high_cardinality_categorical)\n    ])\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:27:49.514981Z","iopub.execute_input":"2025-06-14T07:27:49.515244Z","iopub.status.idle":"2025-06-14T07:27:53.639531Z","shell.execute_reply.started":"2025-06-14T07:27:49.515224Z","shell.execute_reply":"2025-06-14T07:27:53.638696Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = Pipeline(steps=[\n    ('preprocessor', preprocessor),\n    ('regressor', RandomForestRegressor(n_estimators=100, random_state=42, n_jobs=-1))\n])\n\nmodel","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:27:53.640901Z","iopub.execute_input":"2025-06-14T07:27:53.641618Z","iopub.status.idle":"2025-06-14T07:27:53.751411Z","shell.execute_reply.started":"2025-06-14T07:27:53.641592Z","shell.execute_reply":"2025-06-14T07:27:53.750603Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# model.fit(X_train, y_train)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = Pipeline(steps=[\n    ('preprocessor', preprocessor),\n    ('regressor', LGBMRegressor(\n        n_estimators=100,\n        learning_rate=0.1,\n        device_type='gpu',\n        verbosity=1,\n        random_state=42\n    ))\n])\nmodel","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:28:13.358232Z","iopub.execute_input":"2025-06-14T07:28:13.359045Z","iopub.status.idle":"2025-06-14T07:28:13.428951Z","shell.execute_reply.started":"2025-06-14T07:28:13.359019Z","shell.execute_reply":"2025-06-14T07:28:13.428134Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(\n    X_train, y_train,\n    regressor__eval_set=[(X_val, y_val)],\n    regressor__eval_metric='mae',\n    regressor__callbacks=[\n        early_stopping(stopping_rounds=10),\n        log_evaluation(period=10)\n    ]\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:31:19.787413Z","iopub.execute_input":"2025-06-14T07:31:19.787965Z","iopub.status.idle":"2025-06-14T07:31:32.517933Z","shell.execute_reply.started":"2025-06-14T07:31:19.787942Z","shell.execute_reply":"2025-06-14T07:31:32.516872Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Penalty_Seconds'] = df['Penalty'].map({\n    '+3s': 3,\n    '+5s': 5,\n    'Ride Through': 20,\n    'DNS': np.nan,\n    'DNF': np.nan\n}).fillna(0)\n\ndf = df[df['Penalty_Seconds'].notna()]\n\ndf['Tire_Combo'] = df['Tire_Compound_Front'] + '_' + df['Tire_Compound_Rear']\ndf['Temperature_Diff'] = df['Track_Temperature_Celsius'] - df['Ambient_Temperature_Celsius']\n\ntarget = 'Lap_Time_Seconds'\nfeatures = [\n    'Circuit_Length_km', 'Avg_Speed_kmh', 'Corners_per_Lap',\n    'Tire_Degradation_Factor_per_Lap', 'Pit_Stop_Duration_Seconds',\n    'Ambient_Temperature_Celsius', 'Track_Temperature_Celsius', 'Penalty_Seconds',\n    'Temperature_Diff', 'Track_Condition', 'Tire_Compound_Front',\n    'Tire_Compound_Rear', 'Tire_Combo', 'Session', 'circuit_name'\n]\n\nnumerical_features = [\n    'Circuit_Length_km', 'Avg_Speed_kmh', 'Corners_per_Lap',\n    'Tire_Degradation_Factor_per_Lap', 'Pit_Stop_Duration_Seconds',\n    'Ambient_Temperature_Celsius', 'Track_Temperature_Celsius', 'Penalty_Seconds',\n    'Temperature_Diff'\n]\nlow_cardinality_categorical = [\n    'Track_Condition', 'Tire_Compound_Front', 'Tire_Compound_Rear',\n    'Tire_Combo', 'Session'\n]\nhigh_cardinality_categorical = ['circuit_name']\n\nfor col in numerical_features:\n    df[col] = df[col].astype('float32')\ndf[target] = df[target].astype('float32')\n\nX = df[features]\ny = df[target]\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.1, random_state=42)\n\nnumerical_transformer = Pipeline(steps=[\n    ('imputer', SimpleImputer(strategy='median')),\n    ('scaler', StandardScaler())\n])\n\nlow_cardinality_transformer = Pipeline(steps=[\n    ('imputer', SimpleImputer(strategy='constant', fill_value='Unknown')),\n    ('onehot', OneHotEncoder(handle_unknown='ignore', sparse_output=True))\n])\n\nhigh_cardinality_transformer = Pipeline(steps=[\n    ('imputer', SimpleImputer(strategy='constant', fill_value='Unknown')),\n    ('target', ce.TargetEncoder())\n])\n\npreprocessor = ColumnTransformer(\n    transformers=[\n        ('num', numerical_transformer, numerical_features),\n        ('low_cat', low_cardinality_transformer, low_cardinality_categorical),\n        ('high_cat', high_cardinality_transformer, high_cardinality_categorical)\n    ])\n\nX_train_transformed = preprocessor.fit_transform(X_train, y_train)\nX_val_transformed = preprocessor.transform(X_val)\n\nlgbm = LGBMRegressor(\n    n_estimators=5000,\n    learning_rate=0.1,\n    device_type='gpu',\n    verbosity=1,\n    random_state=42\n)\n\nlgbm.fit(\n    X_train_transformed,\n    y_train,\n    eval_set=[(X_val_transformed, y_val)],\n    eval_metric='mae',\n    callbacks=[\n        early_stopping(stopping_rounds=50),\n        log_evaluation(period=10)\n    ]\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:41:52.699366Z","iopub.execute_input":"2025-06-14T07:41:52.699671Z","iopub.status.idle":"2025-06-14T07:43:18.851346Z","shell.execute_reply.started":"2025-06-14T07:41:52.699650Z","shell.execute_reply":"2025-06-14T07:43:18.850596Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = lgbm.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-14T07:46:48.431662Z","iopub.execute_input":"2025-06-14T07:46:48.432018Z","iopub.status.idle":"2025-06-14T07:46:49.401920Z","shell.execute_reply.started":"2025-06-14T07:46:48.431998Z","shell.execute_reply":"2025-06-14T07:46:49.400917Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}