{"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-05T14:58:21.967965Z","iopub.execute_input":"2024-12-05T14:58:21.968323Z","iopub.status.idle":"2024-12-05T14:58:24.78187Z","shell.execute_reply.started":"2024-12-05T14:58:21.968288Z","shell.execute_reply":"2024-12-05T14:58:24.780627Z"}},"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-05T14:58:24.784065Z","iopub.execute_input":"2024-12-05T14:58:24.784707Z","iopub.status.idle":"2024-12-05T14:58:29.069053Z","shell.execute_reply.started":"2024-12-05T14:58:24.784638Z","shell.execute_reply":"2024-12-05T14:58:29.068147Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T14:58:29.070205Z","iopub.execute_input":"2024-12-05T14:58:29.070523Z","iopub.status.idle":"2024-12-05T14:58:29.100845Z","shell.execute_reply.started":"2024-12-05T14:58:29.070492Z","shell.execute_reply":"2024-12-05T14:58:29.099734Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T14:58:29.102608Z","iopub.execute_input":"2024-12-05T14:58:29.102939Z","iopub.status.idle":"2024-12-05T14:58:29.128189Z","shell.execute_reply.started":"2024-12-05T14:58:29.10291Z","shell.execute_reply":"2024-12-05T14:58:29.126947Z"}},"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-05T14:58:29.129755Z","iopub.execute_input":"2024-12-05T14:58:29.130114Z","iopub.status.idle":"2024-12-05T15:02:06.94811Z","shell.execute_reply.started":"2024-12-05T14:58:29.130081Z","shell.execute_reply":"2024-12-05T15:02:06.94708Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:02:06.954182Z","iopub.execute_input":"2024-12-05T15:02:06.954505Z","iopub.status.idle":"2024-12-05T15:02:07.545401Z","shell.execute_reply.started":"2024-12-05T15:02:06.954473Z","shell.execute_reply":"2024-12-05T15:02:07.5443Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:02:07.546847Z","iopub.execute_input":"2024-12-05T15:02:07.547339Z","iopub.status.idle":"2024-12-05T15:02:08.124335Z","shell.execute_reply.started":"2024-12-05T15:02:07.547243Z","shell.execute_reply":"2024-12-05T15:02:08.12318Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"target = 'Premium Amount'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:03:26.284407Z","iopub.execute_input":"2024-12-05T15:03:26.284868Z","iopub.status.idle":"2024-12-05T15:03:26.290075Z","shell.execute_reply.started":"2024-12-05T15:03:26.28483Z","shell.execute_reply":"2024-12-05T15:03:26.288993Z"}},"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-05T15:03:51.106867Z","iopub.execute_input":"2024-12-05T15:03:51.107266Z","iopub.status.idle":"2024-12-05T15:03:51.385892Z","shell.execute_reply.started":"2024-12-05T15:03:51.107232Z","shell.execute_reply":"2024-12-05T15:03:51.384679Z"}},"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-05T15:04:12.1267Z","iopub.execute_input":"2024-12-05T15:04:12.127083Z","iopub.status.idle":"2024-12-05T15:04:12.815486Z","shell.execute_reply.started":"2024-12-05T15:04:12.127051Z","shell.execute_reply":"2024-12-05T15:04:12.814498Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.duplicated().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:04:33.448312Z","iopub.execute_input":"2024-12-05T15:04:33.448752Z","iopub.status.idle":"2024-12-05T15:04:34.861189Z","shell.execute_reply.started":"2024-12-05T15:04:33.448714Z","shell.execute_reply":"2024-12-05T15:04:34.860108Z"}},"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-05T15:04:47.618237Z","iopub.execute_input":"2024-12-05T15:04:47.618723Z","iopub.status.idle":"2024-12-05T15:04:48.539336Z","shell.execute_reply.started":"2024-12-05T15:04:47.618664Z","shell.execute_reply":"2024-12-05T15:04:48.538205Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_df.describe(include='O').T","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:05:09.321572Z","iopub.execute_input":"2024-12-05T15:05:09.321985Z","iopub.status.idle":"2024-12-05T15:05:11.00825Z","shell.execute_reply.started":"2024-12-05T15:05:09.321949Z","shell.execute_reply":"2024-12-05T15:05:11.007146Z"}},"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-05T15:09:14.934506Z","iopub.execute_input":"2024-12-05T15:09:14.934947Z","iopub.status.idle":"2024-12-05T15:09:15.403637Z","shell.execute_reply.started":"2024-12-05T15:09:14.934912Z","shell.execute_reply":"2024-12-05T15:09:15.4026Z"}},"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-05T15:09:42.435113Z","iopub.execute_input":"2024-12-05T15:09:42.435739Z","iopub.status.idle":"2024-12-05T15:09:43.038806Z","shell.execute_reply.started":"2024-12-05T15:09:42.435695Z","shell.execute_reply":"2024-12-05T15:09:43.037608Z"}},"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-05T15:09:58.533089Z","iopub.execute_input":"2024-12-05T15:09:58.53406Z","iopub.status.idle":"2024-12-05T15:10:10.013018Z","shell.execute_reply.started":"2024-12-05T15:09:58.534009Z","shell.execute_reply":"2024-12-05T15:10:10.01187Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = LinearRegression()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:10:35.801084Z","iopub.execute_input":"2024-12-05T15:10:35.801471Z","iopub.status.idle":"2024-12-05T15:10:35.806752Z","shell.execute_reply.started":"2024-12-05T15:10:35.80144Z","shell.execute_reply":"2024-12-05T15:10:35.80559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X,y)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:10:42.766581Z","iopub.execute_input":"2024-12-05T15:10:42.766996Z","iopub.status.idle":"2024-12-05T15:10:44.501267Z","shell.execute_reply.started":"2024-12-05T15:10:42.766962Z","shell.execute_reply":"2024-12-05T15:10:44.500131Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred=model.predict(testProcessed)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-05T15:11:22.943784Z","iopub.execute_input":"2024-12-05T15:11:22.944184Z","iopub.status.idle":"2024-12-05T15:11:22.974477Z","shell.execute_reply.started":"2024-12-05T15:11:22.944147Z","shell.execute_reply":"2024-12-05T15:11:22.972204Z"}},"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-05T15:11:52.213065Z","iopub.execute_input":"2024-12-05T15:11:52.213479Z","iopub.status.idle":"2024-12-05T15:11:54.287408Z","shell.execute_reply.started":"2024-12-05T15:11:52.213444Z","shell.execute_reply":"2024-12-05T15:11:54.286178Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}