{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.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":84896,"databundleVersionId":10305135,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":false,"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\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":"2025-07-17T14:32:22.489873Z","iopub.execute_input":"2025-07-17T14:32:22.490214Z","iopub.status.idle":"2025-07-17T14:32:22.50015Z","shell.execute_reply.started":"2025-07-17T14:32:22.49019Z","shell.execute_reply":"2025-07-17T14:32:22.49854Z"}},"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 \nimport plotly.express as xp\nfrom sklearn.preprocessing import MinMaxScaler, StandardScaler, RobustScaler","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:22.502396Z","iopub.execute_input":"2025-07-17T14:32:22.502729Z","iopub.status.idle":"2025-07-17T14:32:22.525215Z","shell.execute_reply.started":"2025-07-17T14:32:22.502704Z","shell.execute_reply":"2025-07-17T14:32:22.523748Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')\ntest_data = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')\nsample_submission = pd.read_csv('/kaggle/input/playground-series-s4e12/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:22.526357Z","iopub.execute_input":"2025-07-17T14:32:22.526663Z","iopub.status.idle":"2025-07-17T14:32:30.568851Z","shell.execute_reply.started":"2025-07-17T14:32:22.526614Z","shell.execute_reply":"2025-07-17T14:32:30.567953Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:30.57015Z","iopub.execute_input":"2025-07-17T14:32:30.570447Z","iopub.status.idle":"2025-07-17T14:32:31.328375Z","shell.execute_reply.started":"2025-07-17T14:32:30.570425Z","shell.execute_reply":"2025-07-17T14:32:31.327164Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"EDA: Exploration Data Analysis","metadata":{}},{"cell_type":"code","source":"train_data.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:31.331344Z","iopub.execute_input":"2025-07-17T14:32:31.331688Z","iopub.status.idle":"2025-07-17T14:32:32.052944Z","shell.execute_reply.started":"2025-07-17T14:32:31.331659Z","shell.execute_reply":"2025-07-17T14:32:32.051848Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"1-Handling Missing Values","metadata":{}},{"cell_type":"code","source":"train_data.isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:32.053822Z","iopub.execute_input":"2025-07-17T14:32:32.054059Z","iopub.status.idle":"2025-07-17T14:32:32.773721Z","shell.execute_reply.started":"2025-07-17T14:32:32.054041Z","shell.execute_reply":"2025-07-17T14:32:32.772622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.isnull().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:32.774587Z","iopub.execute_input":"2025-07-17T14:32:32.774848Z","iopub.status.idle":"2025-07-17T14:32:33.493581Z","shell.execute_reply.started":"2025-07-17T14:32:32.77483Z","shell.execute_reply":"2025-07-17T14:32:33.492609Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Missing percentage\nmissings = train_data.isnull().mean()*100\nmissings","metadata":{}},{"cell_type":"code","source":"# Missing percentage\nmissings = train_data.isnull().mean()*100\nmissings","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:33.494951Z","iopub.execute_input":"2025-07-17T14:32:33.495301Z","iopub.status.idle":"2025-07-17T14:32:34.197655Z","shell.execute_reply.started":"2025-07-17T14:32:33.495278Z","shell.execute_reply":"2025-07-17T14:32:34.196767Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# handling Age ( mean, mode, median)\nsns.boxplot(x=train_data['Age'])\nplt.title(\"BoxPlot of Age\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:34.19849Z","iopub.execute_input":"2025-07-17T14:32:34.198731Z","iopub.status.idle":"2025-07-17T14:32:34.379927Z","shell.execute_reply.started":"2025-07-17T14:32:34.198711Z","shell.execute_reply":"2025-07-17T14:32:34.378828Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_data['Age'].mean())\nprint(train_data['Age'].median())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:34.380938Z","iopub.execute_input":"2025-07-17T14:32:34.381448Z","iopub.status.idle":"2025-07-17T14:32:34.419683Z","shell.execute_reply.started":"2025-07-17T14:32:34.381418Z","shell.execute_reply":"2025-07-17T14:32:34.418695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Handlung\nsns.boxplot(x=train_data['Annual Income'])\nplt.title(\"BoxPlot of Annual Income\")\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:34.420557Z","iopub.execute_input":"2025-07-17T14:32:34.420874Z","iopub.status.idle":"2025-07-17T14:32:34.776518Z","shell.execute_reply.started":"2025-07-17T14:32:34.420851Z","shell.execute_reply":"2025-07-17T14:32:34.775309Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_data['Annual Income'].mean())\nprint(train_data['Annual Income'].median())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:34.777488Z","iopub.execute_input":"2025-07-17T14:32:34.777918Z","iopub.status.idle":"2025-07-17T14:32:34.824378Z","shell.execute_reply.started":"2025-07-17T14:32:34.777886Z","shell.execute_reply":"2025-07-17T14:32:34.822534Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(x=train_data['Health Score'])\nplt.title('BoxPlot of Health Score')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:34.825539Z","iopub.execute_input":"2025-07-17T14:32:34.825883Z","iopub.status.idle":"2025-07-17T14:32:35.022396Z","shell.execute_reply.started":"2025-07-17T14:32:34.825854Z","shell.execute_reply":"2025-07-17T14:32:35.021355Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train_data['Health Score'].mean())\nprint(train_data['Health Score'].median())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:35.02696Z","iopub.execute_input":"2025-07-17T14:32:35.027273Z","iopub.status.idle":"2025-07-17T14:32:35.069166Z","shell.execute_reply.started":"2025-07-17T14:32:35.027252Z","shell.execute_reply":"2025-07-17T14:32:35.067977Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:35.070204Z","iopub.execute_input":"2025-07-17T14:32:35.070518Z","iopub.status.idle":"2025-07-17T14:32:35.797444Z","shell.execute_reply.started":"2025-07-17T14:32:35.070497Z","shell.execute_reply":"2025-07-17T14:32:35.796434Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:35.799073Z","iopub.execute_input":"2025-07-17T14:32:35.799448Z","iopub.status.idle":"2025-07-17T14:32:35.805927Z","shell.execute_reply.started":"2025-07-17T14:32:35.799419Z","shell.execute_reply":"2025-07-17T14:32:35.804815Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in train_data.columns:\n    print(train_data[col].value_counts(normalize=True))\n    print(\"----------------------------------------------------------------\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:35.807086Z","iopub.execute_input":"2025-07-17T14:32:35.80738Z","iopub.status.idle":"2025-07-17T14:32:37.62404Z","shell.execute_reply.started":"2025-07-17T14:32:35.807359Z","shell.execute_reply":"2025-07-17T14:32:37.622896Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.heatmap(train_data.isnull())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:32:37.625149Z","iopub.execute_input":"2025-07-17T14:32:37.625451Z","iopub.status.idle":"2025-07-17T14:33:15.528306Z","shell.execute_reply.started":"2025-07-17T14:32:37.625429Z","shell.execute_reply":"2025-07-17T14:33:15.527277Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"del train_data['id']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:33:15.529343Z","iopub.execute_input":"2025-07-17T14:33:15.529676Z","iopub.status.idle":"2025-07-17T14:33:15.53501Z","shell.execute_reply.started":"2025-07-17T14:33:15.529625Z","shell.execute_reply":"2025-07-17T14:33:15.53407Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"num = train_data.select_dtypes(include=['int64', 'float64']).columns\ncat = train_data.select_dtypes(include=['object', 'category']).columns\nprint(num.tolist())\nprint('------------------------------------------------------------------------------')\n\nprint(cat.tolist())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:33:15.535881Z","iopub.execute_input":"2025-07-17T14:33:15.536392Z","iopub.status.idle":"2025-07-17T14:33:16.200764Z","shell.execute_reply.started":"2025-07-17T14:33:15.536368Z","shell.execute_reply":"2025-07-17T14:33:16.199833Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"\"\"\"\nnumerical_columns = ['Age' ,'Annual Income' ,'' ]\ncat \ntrain_data.fillna(train_data.mean(), inplace=True)\n#gender, Marital Status\n\"\"\"","metadata":{}},{"cell_type":"code","source":"for col in num:\n    plt.figure(figsize=(15,8))\n    sns.histplot(x=train_data[col] , kde=True , bins = 25, data =train_data)\n    plt.title(f\"Histogram of {col}\")\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:33:16.201697Z","iopub.execute_input":"2025-07-17T14:33:16.202003Z","iopub.status.idle":"2025-07-17T14:34:02.064521Z","shell.execute_reply.started":"2025-07-17T14:33:16.201979Z","shell.execute_reply":"2025-07-17T14:34:02.063161Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":" mean=train_data['Health Score'].mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:02.065889Z","iopub.execute_input":"2025-07-17T14:34:02.066286Z","iopub.status.idle":"2025-07-17T14:34:02.083178Z","shell.execute_reply.started":"2025-07-17T14:34:02.066254Z","shell.execute_reply":"2025-07-17T14:34:02.082192Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"std=train_data['Health Score'].std()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:02.084403Z","iopub.execute_input":"2025-07-17T14:34:02.084827Z","iopub.status.idle":"2025-07-17T14:34:02.098601Z","shell.execute_reply.started":"2025-07-17T14:34:02.084802Z","shell.execute_reply":"2025-07-17T14:34:02.097503Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data['Health Score'].isna().sum()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:02.100024Z","iopub.execute_input":"2025-07-17T14:34:02.100304Z","iopub.status.idle":"2025-07-17T14:34:02.114869Z","shell.execute_reply.started":"2025-07-17T14:34:02.100283Z","shell.execute_reply":"2025-07-17T14:34:02.113899Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"np.random.uniform(mean-std,mean+std, size=train_data['Health Score'].isna().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:02.115837Z","iopub.execute_input":"2025-07-17T14:34:02.116193Z","iopub.status.idle":"2025-07-17T14:34:02.132992Z","shell.execute_reply.started":"2025-07-17T14:34:02.116164Z","shell.execute_reply":"2025-07-17T14:34:02.131788Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#test_data.fillna(test_data.mean() , inplace=True )\n# missing percentage\nfor col in num:\n    print(f\"Column Name : {col}\")\n    print(train_data[col].isnull().mean()*100)\n    m=train_data[col].mean()\n    s=train_data[col].std()\n    si=train_data[col].isna().sum()\n    #pd series\n    train_data[col] = train_data[col].fillna(pd.Series(np.random.uniform(m-s, m+s, size=int(si)),index=train_data[train_data[col].isna()].index))\n    print(f\"Number of missing after Handling : {train_data[col].isnull().mean()*100}\")\n    print(\"----------------------------------------------------------------------------\")\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:02.134085Z","iopub.execute_input":"2025-07-17T14:34:02.134451Z","iopub.status.idle":"2025-07-17T14:34:03.174273Z","shell.execute_reply.started":"2025-07-17T14:34:02.134421Z","shell.execute_reply":"2025-07-17T14:34:03.172703Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.heatmap(train_data.isnull())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:03.175449Z","iopub.execute_input":"2025-07-17T14:34:03.175869Z","iopub.status.idle":"2025-07-17T14:34:38.519277Z","shell.execute_reply.started":"2025-07-17T14:34:03.175838Z","shell.execute_reply":"2025-07-17T14:34:38.51832Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in num:\n    plt.figure(figsize=(15,8))\n    sns.histplot(x=train_data[col] , kde=True , bins = 25 , data= train_data)\n    plt.title(f\"Histogram of {col}\")\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:34:38.520277Z","iopub.execute_input":"2025-07-17T14:34:38.520595Z","iopub.status.idle":"2025-07-17T14:35:26.832442Z","shell.execute_reply.started":"2025-07-17T14:34:38.520567Z","shell.execute_reply":"2025-07-17T14:35:26.830822Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data['Marital Status'].mode()[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:35:26.833582Z","iopub.execute_input":"2025-07-17T14:35:26.834489Z","iopub.status.idle":"2025-07-17T14:35:26.92748Z","shell.execute_reply.started":"2025-07-17T14:35:26.834452Z","shell.execute_reply":"2025-07-17T14:35:26.926223Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for col in cat:\n    print(f\"Column Name : {col}\")\n    print(train_data[col].isnull().mean()*100)\n    \n    train_data[col] = train_data[col].fillna(train_data[col].mode()[0])\n    print(f\"Number of missing after Handling : {train_data[col].isnull().mean()*100}\")\n    print(\"________\")\n    ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:35:26.92849Z","iopub.execute_input":"2025-07-17T14:35:26.928861Z","iopub.status.idle":"2025-07-17T14:35:30.516028Z","shell.execute_reply.started":"2025-07-17T14:35:26.928827Z","shell.execute_reply":"2025-07-17T14:35:30.515028Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#Handling Outlier \n#Boxplot (Health Score , Age ,Credit Score )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:35:30.51749Z","iopub.execute_input":"2025-07-17T14:35:30.517804Z","iopub.status.idle":"2025-07-17T14:35:30.522037Z","shell.execute_reply.started":"2025-07-17T14:35:30.517775Z","shell.execute_reply":"2025-07-17T14:35:30.520676Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(x=train_data[\"Health Score\"])\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:35:30.523214Z","iopub.execute_input":"2025-07-17T14:35:30.523555Z","iopub.status.idle":"2025-07-17T14:35:30.732884Z","shell.execute_reply.started":"2025-07-17T14:35:30.523526Z","shell.execute_reply":"2025-07-17T14:35:30.730881Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.boxplot(x=train_data[\"Age\"])\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:36:11.287614Z","iopub.execute_input":"2025-07-17T14:36:11.287985Z","iopub.status.idle":"2025-07-17T14:36:11.465098Z","shell.execute_reply.started":"2025-07-17T14:36:11.28795Z","shell.execute_reply":"2025-07-17T14:36:11.463675Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"sns.boxplot(x=train_data[\"Credit Score\"])\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-17T14:35:48.345259Z","iopub.execute_input":"2025-07-17T14:35:48.345579Z","iopub.status.idle":"2025-07-17T14:35:48.532186Z","shell.execute_reply.started":"2025-07-17T14:35:48.345557Z","shell.execute_reply":"2025-07-17T14:35:48.531059Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}