{"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":84896,"databundleVersionId":10305135,"sourceType":"competition"}],"dockerImageVersionId":30804,"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 matplotlib.pyplot as plt\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.metrics import accuracy_score, mean_squared_error\nimport warnings\n\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:11:22.208081Z","iopub.execute_input":"2024-12-06T17:11:22.208407Z","iopub.status.idle":"2024-12-06T17:11:24.416152Z","shell.execute_reply.started":"2024-12-06T17:11:22.20837Z","shell.execute_reply":"2024-12-06T17:11:24.414977Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv', index_col='id', engine='pyarrow')\ntest_df = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv', index_col='id', engine='pyarrow')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:11:24.418758Z","iopub.execute_input":"2024-12-06T17:11:24.419374Z","iopub.status.idle":"2024-12-06T17:11:27.54829Z","shell.execute_reply.started":"2024-12-06T17:11:24.419324Z","shell.execute_reply":"2024-12-06T17:11:27.547191Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:11:27.549851Z","iopub.execute_input":"2024-12-06T17:11:27.550274Z","iopub.status.idle":"2024-12-06T17:11:27.591897Z","shell.execute_reply.started":"2024-12-06T17:11:27.55023Z","shell.execute_reply":"2024-12-06T17:11:27.590867Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:11:27.593087Z","iopub.execute_input":"2024-12-06T17:11:27.593389Z","iopub.status.idle":"2024-12-06T17:11:27.618614Z","shell.execute_reply.started":"2024-12-06T17:11:27.593359Z","shell.execute_reply":"2024-12-06T17:11:27.617187Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def date_separator(x):\n    return pd.Series([x.day, x.month, x.year])\n\ntrain_df[['day', 'month', 'year']] = train_df['Policy Start Date'].apply(date_separator)\ntest_df[['day', 'month', 'year']] = test_df['Policy Start Date'].apply(date_separator)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:11:27.620169Z","iopub.execute_input":"2024-12-06T17:11:27.620503Z","iopub.status.idle":"2024-12-06T17:15:00.589267Z","shell.execute_reply.started":"2024-12-06T17:11:27.620462Z","shell.execute_reply":"2024-12-06T17:15:00.588042Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:00.59069Z","iopub.execute_input":"2024-12-06T17:15:00.591107Z","iopub.status.idle":"2024-12-06T17:15:01.182384Z","shell.execute_reply.started":"2024-12-06T17:15:00.591069Z","shell.execute_reply":"2024-12-06T17:15:01.181189Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:01.185335Z","iopub.execute_input":"2024-12-06T17:15:01.185736Z","iopub.status.idle":"2024-12-06T17:15:01.755567Z","shell.execute_reply.started":"2024-12-06T17:15:01.185678Z","shell.execute_reply":"2024-12-06T17:15:01.754461Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target = 'Premium Amount'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:01.756691Z","iopub.execute_input":"2024-12-06T17:15:01.75702Z","iopub.status.idle":"2024-12-06T17:15:01.761867Z","shell.execute_reply.started":"2024-12-06T17:15:01.75699Z","shell.execute_reply":"2024-12-06T17:15:01.760803Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"numerical_features = train_df.drop(target, axis=1).select_dtypes(include=np.number).columns.values\nnumerical_features","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:01.763358Z","iopub.execute_input":"2024-12-06T17:15:01.763851Z","iopub.status.idle":"2024-12-06T17:15:02.026619Z","shell.execute_reply.started":"2024-12-06T17:15:01.763796Z","shell.execute_reply":"2024-12-06T17:15:02.025571Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"categorical_features = train_df.drop(target, axis=1).select_dtypes(include='object').columns.values\ncategorical_features","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:02.02801Z","iopub.execute_input":"2024-12-06T17:15:02.028345Z","iopub.status.idle":"2024-12-06T17:15:02.697197Z","shell.execute_reply.started":"2024-12-06T17:15:02.028312Z","shell.execute_reply":"2024-12-06T17:15:02.696155Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.duplicated().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:02.698552Z","iopub.execute_input":"2024-12-06T17:15:02.698946Z","iopub.status.idle":"2024-12-06T17:15:04.065303Z","shell.execute_reply.started":"2024-12-06T17:15:02.698914Z","shell.execute_reply":"2024-12-06T17:15:04.064116Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df[numerical_features].astype(np.float_).describe().T","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:04.066823Z","iopub.execute_input":"2024-12-06T17:15:04.067685Z","iopub.status.idle":"2024-12-06T17:15:04.958861Z","shell.execute_reply.started":"2024-12-06T17:15:04.067631Z","shell.execute_reply":"2024-12-06T17:15:04.957769Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.describe(include='O').T","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:04.960058Z","iopub.execute_input":"2024-12-06T17:15:04.960381Z","iopub.status.idle":"2024-12-06T17:15:06.609994Z","shell.execute_reply.started":"2024-12-06T17:15:04.960352Z","shell.execute_reply":"2024-12-06T17:15:06.608936Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler, FunctionTransformer, LabelEncoder, OneHotEncoder\nfrom sklearn.pipeline import make_pipeline, Pipeline\nfrom sklearn.compose import ColumnTransformer, make_column_selector, make_column_transformer\nfrom sklearn.experimental import enable_iterative_imputer\nfrom sklearn.impute import SimpleImputer, IterativeImputer\nimport category_encoders as ce\n\npreprocessing = ColumnTransformer([\n    ('num', make_pipeline(SimpleImputer(strategy='mean'), FunctionTransformer(), StandardScaler()), numerical_features),\n    ('cat', make_pipeline(SimpleImputer(strategy='most_frequent'), ce.cat_boost.CatBoostEncoder()), categorical_features)\n], remainder='drop')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:06.611339Z","iopub.execute_input":"2024-12-06T17:15:06.611678Z","iopub.status.idle":"2024-12-06T17:15:07.17228Z","shell.execute_reply.started":"2024-12-06T17:15:06.611646Z","shell.execute_reply":"2024-12-06T17:15:07.171301Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = train_df.copy()\ny = X.pop(target)\ny = np.log1p(y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:07.174118Z","iopub.execute_input":"2024-12-06T17:15:07.174775Z","iopub.status.idle":"2024-12-06T17:15:07.760682Z","shell.execute_reply.started":"2024-12-06T17:15:07.174707Z","shell.execute_reply":"2024-12-06T17:15:07.75951Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = preprocessing.fit_transform(X, y)\ntestProcessed = preprocessing.transform(test_df)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:07.761984Z","iopub.execute_input":"2024-12-06T17:15:07.762316Z","iopub.status.idle":"2024-12-06T17:15:19.068251Z","shell.execute_reply.started":"2024-12-06T17:15:07.762285Z","shell.execute_reply":"2024-12-06T17:15:19.067103Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = LinearRegression()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:19.069577Z","iopub.execute_input":"2024-12-06T17:15:19.070046Z","iopub.status.idle":"2024-12-06T17:15:19.075814Z","shell.execute_reply.started":"2024-12-06T17:15:19.070001Z","shell.execute_reply":"2024-12-06T17:15:19.074545Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X,y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:19.077136Z","iopub.execute_input":"2024-12-06T17:15:19.077477Z","iopub.status.idle":"2024-12-06T17:15:20.751276Z","shell.execute_reply.started":"2024-12-06T17:15:19.077445Z","shell.execute_reply":"2024-12-06T17:15:20.750276Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred=model.predict(testProcessed)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:20.752339Z","iopub.execute_input":"2024-12-06T17:15:20.752686Z","iopub.status.idle":"2024-12-06T17:15:20.779483Z","shell.execute_reply.started":"2024-12-06T17:15:20.752654Z","shell.execute_reply":"2024-12-06T17:15:20.778032Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sub = pd.read_csv(\"/kaggle/input/playground-series-s4e12/sample_submission.csv\")\nsub[target] = np.expm1(y_pred)\nsub.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-06T17:15:20.781155Z","iopub.execute_input":"2024-12-06T17:15:20.78398Z","iopub.status.idle":"2024-12-06T17:15:22.74703Z","shell.execute_reply.started":"2024-12-06T17:15:20.781659Z","shell.execute_reply":"2024-12-06T17:15:22.745751Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}