{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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\nimport matplotlib.pyplot as plt\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,"execution":{"iopub.status.busy":"2024-12-20T13:37:25.312157Z","iopub.execute_input":"2024-12-20T13:37:25.312485Z","iopub.status.idle":"2024-12-20T13:37:25.327844Z","shell.execute_reply.started":"2024-12-20T13:37:25.31246Z","shell.execute_reply":"2024-12-20T13:37:25.326587Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train = pd.read_csv(\"/kaggle/input/playground-series-s4e12/train.csv\")\ndf_test = pd.read_csv(\"/kaggle/input/playground-series-s4e12/test.csv\")\nsub = pd.read_csv(\"/kaggle/input/playground-series-s4e12/sample_submission.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:25.329359Z","iopub.execute_input":"2024-12-20T13:37:25.329741Z","iopub.status.idle":"2024-12-20T13:37:32.631359Z","shell.execute_reply.started":"2024-12-20T13:37:25.329716Z","shell.execute_reply":"2024-12-20T13:37:32.630525Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:32.633148Z","iopub.execute_input":"2024-12-20T13:37:32.633396Z","iopub.status.idle":"2024-12-20T13:37:33.26646Z","shell.execute_reply.started":"2024-12-20T13:37:32.633375Z","shell.execute_reply":"2024-12-20T13:37:33.265326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"FEATURES = [c for c in df_test.columns if c != \"id\"]\n\nCAT_COLUMNS = df_train[FEATURES].select_dtypes(include=['object']).columns.tolist()\nCAT_COLUMNS = [c for c in CAT_COLUMNS if c not in [\"Policy Start Date\"]]\nNUM_COLUMNS = df_train[FEATURES].select_dtypes(include=['float64', \"int64\"]).columns.tolist()\nNUM_COLUMNS = [c for c in NUM_COLUMNS if c not in [\"Customer Feedback\"]]\n\nLABEL = \"Premium Amount\"\n\ndf_train[NUM_COLUMNS] = df_train[NUM_COLUMNS].fillna(-1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:33.267776Z","iopub.execute_input":"2024-12-20T13:37:33.26804Z","iopub.status.idle":"2024-12-20T13:37:33.967302Z","shell.execute_reply.started":"2024-12-20T13:37:33.268016Z","shell.execute_reply":"2024-12-20T13:37:33.96652Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"NUM_COLUMNS","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:38:55.658119Z","iopub.execute_input":"2024-12-20T13:38:55.658494Z","iopub.status.idle":"2024-12-20T13:38:55.664405Z","shell.execute_reply.started":"2024-12-20T13:38:55.658425Z","shell.execute_reply":"2024-12-20T13:38:55.663323Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Analyse feature *Vehicle Age*","metadata":{}},{"cell_type":"markdown","source":"We can see in this graph that Nan values in this column are related to rather small values in the target :","metadata":{}},{"cell_type":"code","source":"COL = \"Vehicle Age\"\n\nx = df_train[COL]\ny = df_train[LABEL]\n\nplt.scatter(x,y)\n\nplt.xlabel(COL)\nplt.ylabel(LABEL)\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:33.968201Z","iopub.execute_input":"2024-12-20T13:37:33.968491Z","iopub.status.idle":"2024-12-20T13:37:36.732181Z","shell.execute_reply.started":"2024-12-20T13:37:33.968457Z","shell.execute_reply":"2024-12-20T13:37:36.731236Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Let us check which is the limit of these small values : ","metadata":{}},{"cell_type":"code","source":"dfxx = df_train.loc[:,[COL,LABEL]]\ndf_nan = dfxx[dfxx[COL] == -1] \ndf_nan.max(axis=0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:36.733123Z","iopub.execute_input":"2024-12-20T13:37:36.733388Z","iopub.status.idle":"2024-12-20T13:37:36.751714Z","shell.execute_reply.started":"2024-12-20T13:37:36.733355Z","shell.execute_reply":"2024-12-20T13:37:36.750778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_nan.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:36.752674Z","iopub.execute_input":"2024-12-20T13:37:36.752933Z","iopub.status.idle":"2024-12-20T13:37:36.771442Z","shell.execute_reply.started":"2024-12-20T13:37:36.752912Z","shell.execute_reply":"2024-12-20T13:37:36.770542Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x = df_nan[LABEL].sort_values()\ny = list(range(df_nan.shape[0]))\n\nplt.plot(x, y, 'o')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:37:36.773349Z","iopub.execute_input":"2024-12-20T13:37:36.773651Z","iopub.status.idle":"2024-12-20T13:37:36.970497Z","shell.execute_reply.started":"2024-12-20T13:37:36.773626Z","shell.execute_reply":"2024-12-20T13:37:36.969414Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### Analyse feature *Health Score*","metadata":{}},{"cell_type":"code","source":"COL = \"Health Score\"\n\nx = df_train[COL]\ny = df_train[LABEL]\n\nplt.scatter(x,y)\n\nplt.xlabel(COL)\nplt.ylabel(LABEL)\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:43:05.823564Z","iopub.execute_input":"2024-12-20T13:43:05.823921Z","iopub.status.idle":"2024-12-20T13:43:08.554464Z","shell.execute_reply.started":"2024-12-20T13:43:05.823894Z","shell.execute_reply":"2024-12-20T13:43:08.553387Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"We can isolate in a rough way, a part of this dataframe where nan values are absent :","metadata":{}},{"cell_type":"code","source":"df_hs = df_train[(df_train[LABEL] > 1800) & (df_train[LABEL] < 2200)]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:45:15.293028Z","iopub.execute_input":"2024-12-20T13:45:15.293334Z","iopub.status.idle":"2024-12-20T13:45:15.338705Z","shell.execute_reply.started":"2024-12-20T13:45:15.293311Z","shell.execute_reply":"2024-12-20T13:45:15.337674Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"We can see it better if we zoom on it :","metadata":{}},{"cell_type":"code","source":"\nx = df_hs[COL]\ny = df_hs[LABEL]\n\nplt.scatter(x,y)\n\nplt.xlabel(COL)\nplt.ylabel(LABEL)\n\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T13:45:17.638369Z","iopub.execute_input":"2024-12-20T13:45:17.63877Z","iopub.status.idle":"2024-12-20T13:45:17.992599Z","shell.execute_reply.started":"2024-12-20T13:45:17.63874Z","shell.execute_reply":"2024-12-20T13:45:17.991493Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}