{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.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":2551,"databundleVersionId":29345,"sourceType":"competition"}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"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)\nimport seaborn as sns\nimport matplotlib.pyplot as plt\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","execution":{"iopub.status.busy":"2024-03-04T02:52:12.586040Z","iopub.execute_input":"2024-03-04T02:52:12.586495Z","iopub.status.idle":"2024-03-04T02:52:12.597981Z","shell.execute_reply.started":"2024-03-04T02:52:12.586464Z","shell.execute_reply":"2024-03-04T02:52:12.596759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test =pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-test.csv')\ntest.head()\n\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:12.600818Z","iopub.execute_input":"2024-03-04T02:52:12.601277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train =pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-training.csv')\ntrain.head()","metadata":{"execution":{"iopub.status.idle":"2024-03-04T02:52:12.984750Z","shell.execute_reply.started":"2024-03-04T02:52:12.770774Z","shell.execute_reply":"2024-03-04T02:52:12.983693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.duplicated().sum()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:12.988252Z","iopub.execute_input":"2024-03-04T02:52:12.988595Z","iopub.status.idle":"2024-03-04T02:52:13.049772Z","shell.execute_reply.started":"2024-03-04T02:52:12.988566Z","shell.execute_reply":"2024-03-04T02:52:13.048799Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.duplicated().value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.051414Z","iopub.execute_input":"2024-03-04T02:52:13.051859Z","iopub.status.idle":"2024-03-04T02:52:13.113967Z","shell.execute_reply.started":"2024-03-04T02:52:13.051818Z","shell.execute_reply":"2024-03-04T02:52:13.112934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup=train.drop_duplicates()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.115244Z","iopub.execute_input":"2024-03-04T02:52:13.115688Z","iopub.status.idle":"2024-03-04T02:52:13.176223Z","shell.execute_reply.started":"2024-03-04T02:52:13.115649Z","shell.execute_reply":"2024-03-04T02:52:13.175271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.177515Z","iopub.execute_input":"2024-03-04T02:52:13.177877Z","iopub.status.idle":"2024-03-04T02:52:13.195795Z","shell.execute_reply.started":"2024-03-04T02:52:13.177846Z","shell.execute_reply":"2024-03-04T02:52:13.194806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.197813Z","iopub.execute_input":"2024-03-04T02:52:13.198223Z","iopub.status.idle":"2024-03-04T02:52:13.210831Z","shell.execute_reply.started":"2024-03-04T02:52:13.198188Z","shell.execute_reply":"2024-03-04T02:52:13.209803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"round(train_redup.isnull().sum()/train_redup.shape[0]*100,2)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.212228Z","iopub.execute_input":"2024-03-04T02:52:13.212877Z","iopub.status.idle":"2024-03-04T02:52:13.225428Z","shell.execute_reply.started":"2024-03-04T02:52:13.212842Z","shell.execute_reply":"2024-03-04T02:52:13.223951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def findMiss(df):\n    return round(df.isnull().sum()/df.shape[0]*100,2)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.230183Z","iopub.execute_input":"2024-03-04T02:52:13.230574Z","iopub.status.idle":"2024-03-04T02:52:13.235867Z","shell.execute_reply.started":"2024-03-04T02:52:13.230541Z","shell.execute_reply":"2024-03-04T02:52:13.234892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup[train_redup.NumberOfDependents.isnull()]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.237206Z","iopub.execute_input":"2024-03-04T02:52:13.237781Z","iopub.status.idle":"2024-03-04T02:52:13.266815Z","shell.execute_reply.started":"2024-03-04T02:52:13.237747Z","shell.execute_reply":"2024-03-04T02:52:13.265745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup[train_redup.NumberOfDependents.isnull()].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.268284Z","iopub.execute_input":"2024-03-04T02:52:13.268646Z","iopub.status.idle":"2024-03-04T02:52:13.319325Z","shell.execute_reply.started":"2024-03-04T02:52:13.268603Z","shell.execute_reply":"2024-03-04T02:52:13.318385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup[train_redup.MonthlyIncome.isnull()].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.320734Z","iopub.execute_input":"2024-03-04T02:52:13.321604Z","iopub.status.idle":"2024-03-04T02:52:13.382494Z","shell.execute_reply.started":"2024-03-04T02:52:13.321570Z","shell.execute_reply":"2024-03-04T02:52:13.381170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup['NumberOfDependents'].agg(['mode'])","metadata":{"execution":{"iopub.execute_input":"2024-03-04T02:52:13.385991Z","iopub.status.idle":"2024-03-04T02:52:13.403370Z","shell.execute_reply.started":"2024-03-04T02:52:13.385945Z","shell.execute_reply":"2024-03-04T02:52:13.402104Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_redup.groupby(['NumberOfDependents']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.405211Z","iopub.execute_input":"2024-03-04T02:52:13.405585Z","iopub.status.idle":"2024-03-04T02:52:13.421938Z","shell.execute_reply.started":"2024-03-04T02:52:13.405553Z","shell.execute_reply":"2024-03-04T02:52:13.420577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_miss= train_redup[train_redup.NumberOfDependents.isnull()]\nfam_nmiss=train_redup[train_redup.NumberOfDependents.notnull()]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.423092Z","iopub.execute_input":"2024-03-04T02:52:13.423442Z","iopub.status.idle":"2024-03-04T02:52:13.439811Z","shell.execute_reply.started":"2024-03-04T02:52:13.423412Z","shell.execute_reply":"2024-03-04T02:52:13.438553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_miss['NumberOfDependents']= fam_miss['NumberOfDependents'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.441221Z","iopub.execute_input":"2024-03-04T02:52:13.441608Z","iopub.status.idle":"2024-03-04T02:52:13.449968Z","shell.execute_reply.started":"2024-03-04T02:52:13.441577Z","shell.execute_reply":"2024-03-04T02:52:13.448848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_miss.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.452276Z","iopub.execute_input":"2024-03-04T02:52:13.452642Z","iopub.status.idle":"2024-03-04T02:52:13.462598Z","shell.execute_reply.started":"2024-03-04T02:52:13.452610Z","shell.execute_reply":"2024-03-04T02:52:13.461299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_nmiss.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.464178Z","iopub.execute_input":"2024-03-04T02:52:13.464602Z","iopub.status.idle":"2024-03-04T02:52:13.473636Z","shell.execute_reply.started":"2024-03-04T02:52:13.464570Z","shell.execute_reply":"2024-03-04T02:52:13.472533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_miss['NumberOfDependents']= fam_miss['NumberOfDependents'].fillna(0)\nfam_miss['MonthlyIncome']= fam_miss['MonthlyIncome'].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.475430Z","iopub.execute_input":"2024-03-04T02:52:13.476178Z","iopub.status.idle":"2024-03-04T02:52:13.488241Z","shell.execute_reply.started":"2024-03-04T02:52:13.476125Z","shell.execute_reply":"2024-03-04T02:52:13.484057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"findMiss(fam_miss)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.490212Z","iopub.execute_input":"2024-03-04T02:52:13.490691Z","iopub.status.idle":"2024-03-04T02:52:13.504886Z","shell.execute_reply.started":"2024-03-04T02:52:13.490659Z","shell.execute_reply":"2024-03-04T02:52:13.503794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"findMiss(fam_nmiss)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.506689Z","iopub.execute_input":"2024-03-04T02:52:13.507422Z","iopub.status.idle":"2024-03-04T02:52:13.525053Z","shell.execute_reply.started":"2024-03-04T02:52:13.507379Z","shell.execute_reply":"2024-03-04T02:52:13.523931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_nmiss['MonthlyIncome'].agg(['mean','median','min'])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.526832Z","iopub.execute_input":"2024-03-04T02:52:13.527519Z","iopub.status.idle":"2024-03-04T02:52:13.547016Z","shell.execute_reply.started":"2024-03-04T02:52:13.527476Z","shell.execute_reply":"2024-03-04T02:52:13.545888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_nmiss['MonthlyIncome'].agg(['max'])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.548625Z","iopub.execute_input":"2024-03-04T02:52:13.549297Z","iopub.status.idle":"2024-03-04T02:52:13.560792Z","shell.execute_reply.started":"2024-03-04T02:52:13.549256Z","shell.execute_reply":"2024-03-04T02:52:13.559673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fam_nmiss['MonthlyIncome']= fam_nmiss['MonthlyIncome'].fillna(fam_nmiss['MonthlyIncome'].median())","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.562365Z","iopub.execute_input":"2024-03-04T02:52:13.563204Z","iopub.status.idle":"2024-03-04T02:52:13.575470Z","shell.execute_reply.started":"2024-03-04T02:52:13.563163Z","shell.execute_reply":"2024-03-04T02:52:13.574421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"findMiss(fam_nmiss)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.577407Z","iopub.execute_input":"2024-03-04T02:52:13.578080Z","iopub.status.idle":"2024-03-04T02:52:13.591292Z","shell.execute_reply.started":"2024-03-04T02:52:13.578038Z","shell.execute_reply":"2024-03-04T02:52:13.590150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"findMiss(fam_miss)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.592939Z","iopub.execute_input":"2024-03-04T02:52:13.593593Z","iopub.status.idle":"2024-03-04T02:52:13.604985Z","shell.execute_reply.started":"2024-03-04T02:52:13.593552Z","shell.execute_reply":"2024-03-04T02:52:13.603811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train=fam_nmiss._append(fam_miss)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.612115Z","iopub.execute_input":"2024-03-04T02:52:13.612868Z","iopub.status.idle":"2024-03-04T02:52:13.622488Z","shell.execute_reply.started":"2024-03-04T02:52:13.612824Z","shell.execute_reply":"2024-03-04T02:52:13.621336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.627816Z","iopub.execute_input":"2024-03-04T02:52:13.628204Z","iopub.status.idle":"2024-03-04T02:52:13.634960Z","shell.execute_reply.started":"2024-03-04T02:52:13.628167Z","shell.execute_reply":"2024-03-04T02:52:13.633895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"findMiss(filled_train)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:52:13.636640Z","iopub.execute_input":"2024-03-04T02:52:13.637321Z","iopub.status.idle":"2024-03-04T02:52:13.657579Z","shell.execute_reply.started":"2024-03-04T02:52:13.637279Z","shell.execute_reply":"2024-03-04T02:52:13.656409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:56:53.935405Z","iopub.execute_input":"2024-03-04T02:56:53.935887Z","iopub.status.idle":"2024-03-04T02:56:53.956022Z","shell.execute_reply.started":"2024-03-04T02:56:53.935850Z","shell.execute_reply":"2024-03-04T02:56:53.954774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train.groupby(['SeriousDlqin2yrs']).size()/filled_train.shape[0]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:56:57.505665Z","iopub.execute_input":"2024-03-04T02:56:57.506146Z","iopub.status.idle":"2024-03-04T02:56:57.517590Z","shell.execute_reply.started":"2024-03-04T02:56:57.506111Z","shell.execute_reply":"2024-03-04T02:56:57.516313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train.RevolvingUtilizationOfUnsecuredLines.describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:04.155658Z","iopub.execute_input":"2024-03-04T02:57:04.156473Z","iopub.status.idle":"2024-03-04T02:57:04.174674Z","shell.execute_reply.started":"2024-03-04T02:57:04.156434Z","shell.execute_reply":"2024-03-04T02:57:04.173446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train['RevolvingUtilizationOfUnsecuredLines'].quantile([.99])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:12.899929Z","iopub.execute_input":"2024-03-04T02:57:12.900360Z","iopub.status.idle":"2024-03-04T02:57:12.911148Z","shell.execute_reply.started":"2024-03-04T02:57:12.900325Z","shell.execute_reply":"2024-03-04T02:57:12.909968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train[filled_train['RevolvingUtilizationOfUnsecuredLines'] < 1].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:21.109945Z","iopub.execute_input":"2024-03-04T02:57:21.110332Z","iopub.status.idle":"2024-03-04T02:57:21.233040Z","shell.execute_reply.started":"2024-03-04T02:57:21.110301Z","shell.execute_reply":"2024-03-04T02:57:21.231838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train[filled_train['RevolvingUtilizationOfUnsecuredLines'] > 1].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:29.104952Z","iopub.execute_input":"2024-03-04T02:57:29.105357Z","iopub.status.idle":"2024-03-04T02:57:29.156120Z","shell.execute_reply.started":"2024-03-04T02:57:29.105323Z","shell.execute_reply":"2024-03-04T02:57:29.154821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filled_train[filled_train['RevolvingUtilizationOfUnsecuredLines'] >10].groupby(['SeriousDlqin2yrs']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:35.135817Z","iopub.execute_input":"2024-03-04T02:57:35.136217Z","iopub.status.idle":"2024-03-04T02:57:35.148322Z","shell.execute_reply.started":"2024-03-04T02:57:35.136185Z","shell.execute_reply":"2024-03-04T02:57:35.147146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped=filled_train.drop(filled_train[filled_train['RevolvingUtilizationOfUnsecuredLines'] >10].index)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:41.339895Z","iopub.execute_input":"2024-03-04T02:57:41.340974Z","iopub.status.idle":"2024-03-04T02:57:41.348127Z","shell.execute_reply.started":"2024-03-04T02:57:41.340934Z","shell.execute_reply":"2024-03-04T02:57:41.347089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(util_droped['age'])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:57:43.995295Z","iopub.execute_input":"2024-03-04T02:57:43.995683Z","iopub.status.idle":"2024-03-04T02:57:44.230912Z","shell.execute_reply.started":"2024-03-04T02:57:43.995652Z","shell.execute_reply":"2024-03-04T02:57:44.229527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped.groupby(['NumberOfTime30-59DaysPastDueNotWorse']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:59:39.585596Z","iopub.execute_input":"2024-03-04T02:59:39.586075Z","iopub.status.idle":"2024-03-04T02:59:39.597974Z","shell.execute_reply.started":"2024-03-04T02:59:39.586039Z","shell.execute_reply":"2024-03-04T02:59:39.596736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped.groupby(['NumberOfTime60-89DaysPastDueNotWorse']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:59:44.745047Z","iopub.execute_input":"2024-03-04T02:59:44.745463Z","iopub.status.idle":"2024-03-04T02:59:44.756776Z","shell.execute_reply.started":"2024-03-04T02:59:44.745429Z","shell.execute_reply":"2024-03-04T02:59:44.755575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped.groupby(['NumberOfTimes90DaysLate']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T02:59:53.894790Z","iopub.execute_input":"2024-03-04T02:59:53.895190Z","iopub.status.idle":"2024-03-04T02:59:53.907369Z","shell.execute_reply.started":"2024-03-04T02:59:53.895158Z","shell.execute_reply":"2024-03-04T02:59:53.906374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped[util_droped['NumberOfTimes90DaysLate']>=96]['SeriousDlqin2yrs'].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:00.564846Z","iopub.execute_input":"2024-03-04T03:00:00.565242Z","iopub.status.idle":"2024-03-04T03:00:00.577275Z","shell.execute_reply.started":"2024-03-04T03:00:00.565210Z","shell.execute_reply":"2024-03-04T03:00:00.576045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped[util_droped['NumberOfTimes90DaysLate']>=96].groupby(['SeriousDlqin2yrs']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:08.265970Z","iopub.execute_input":"2024-03-04T03:00:08.266379Z","iopub.status.idle":"2024-03-04T03:00:08.279016Z","shell.execute_reply.started":"2024-03-04T03:00:08.266349Z","shell.execute_reply":"2024-03-04T03:00:08.277652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:14.591949Z","iopub.execute_input":"2024-03-04T03:00:14.592364Z","iopub.status.idle":"2024-03-04T03:00:14.610814Z","shell.execute_reply.started":"2024-03-04T03:00:14.592330Z","shell.execute_reply":"2024-03-04T03:00:14.609570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped['DebtRatio'].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:20.370124Z","iopub.execute_input":"2024-03-04T03:00:20.370516Z","iopub.status.idle":"2024-03-04T03:00:20.389656Z","shell.execute_reply.started":"2024-03-04T03:00:20.370486Z","shell.execute_reply":"2024-03-04T03:00:20.388363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.kdeplot(util_droped['DebtRatio'])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:27.805315Z","iopub.execute_input":"2024-03-04T03:00:27.805745Z","iopub.status.idle":"2024-03-04T03:00:28.887365Z","shell.execute_reply.started":"2024-03-04T03:00:27.805691Z","shell.execute_reply":"2024-03-04T03:00:28.886206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped[util_droped['DebtRatio']>3000]['SeriousDlqin2yrs'].describe()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:37.041238Z","iopub.execute_input":"2024-03-04T03:00:37.041620Z","iopub.status.idle":"2024-03-04T03:00:37.059797Z","shell.execute_reply.started":"2024-03-04T03:00:37.041589Z","shell.execute_reply":"2024-03-04T03:00:37.058453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"util_droped[util_droped['DebtRatio']>3000].groupby(['SeriousDlqin2yrs']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:00:44.805618Z","iopub.execute_input":"2024-03-04T03:00:44.806033Z","iopub.status.idle":"2024-03-04T03:00:44.818776Z","shell.execute_reply.started":"2024-03-04T03:00:44.806003Z","shell.execute_reply":"2024-03-04T03:00:44.817329Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp = util_droped[(util_droped['DebtRatio']>3492 ) & (util_droped['SeriousDlqin2yrs']\n                                                       == util_droped['MonthlyIncome'])].describe()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:01.730528Z","iopub.execute_input":"2024-03-04T03:01:01.730922Z","iopub.status.idle":"2024-03-04T03:01:01.751779Z","shell.execute_reply.started":"2024-03-04T03:01:01.730891Z","shell.execute_reply":"2024-03-04T03:01:01.750491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp.groupby(['SeriousDlqin2yrs']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:04.429758Z","iopub.execute_input":"2024-03-04T03:01:04.430438Z","iopub.status.idle":"2024-03-04T03:01:04.440387Z","shell.execute_reply.started":"2024-03-04T03:01:04.430402Z","shell.execute_reply":"2024-03-04T03:01:04.438820Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dRatio = util_droped.drop(util_droped[(util_droped['DebtRatio']>3492 ) & (util_droped['SeriousDlqin2yrs']\n                                                       == util_droped['MonthlyIncome'])].index)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:13.145184Z","iopub.execute_input":"2024-03-04T03:01:13.145622Z","iopub.status.idle":"2024-03-04T03:01:13.164356Z","shell.execute_reply.started":"2024-03-04T03:01:13.145587Z","shell.execute_reply":"2024-03-04T03:01:13.163012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dRatio.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:18.900289Z","iopub.execute_input":"2024-03-04T03:01:18.900706Z","iopub.status.idle":"2024-03-04T03:01:18.908362Z","shell.execute_reply.started":"2024-03-04T03:01:18.900672Z","shell.execute_reply":"2024-03-04T03:01:18.907162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dRatio.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:21.945469Z","iopub.execute_input":"2024-03-04T03:01:21.945928Z","iopub.status.idle":"2024-03-04T03:01:21.964019Z","shell.execute_reply.started":"2024-03-04T03:01:21.945890Z","shell.execute_reply":"2024-03-04T03:01:21.962239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dRatio.shape\ndRatio.groupby('SeriousDlqin2yrs').size()/dRatio.shape[0]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:28.791006Z","iopub.execute_input":"2024-03-04T03:01:28.791470Z","iopub.status.idle":"2024-03-04T03:01:28.803480Z","shell.execute_reply.started":"2024-03-04T03:01:28.791434Z","shell.execute_reply":"2024-03-04T03:01:28.802324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pip install Xgboost","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:01:38.146698Z","iopub.execute_input":"2024-03-04T03:01:38.147133Z","iopub.status.idle":"2024-03-04T03:01:52.854495Z","shell.execute_reply.started":"2024-03-04T03:01:38.147093Z","shell.execute_reply":"2024-03-04T03:01:52.852969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.metrics import confusion_matrix,classification_report","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:02:03.350077Z","iopub.execute_input":"2024-03-04T03:02:03.350470Z","iopub.status.idle":"2024-03-04T03:02:03.356232Z","shell.execute_reply.started":"2024-03-04T03:02:03.350439Z","shell.execute_reply":"2024-03-04T03:02:03.355022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = XGBClassifier(tree_method = 'exact')","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:02:10.719762Z","iopub.execute_input":"2024-03-04T03:02:10.720405Z","iopub.status.idle":"2024-03-04T03:02:10.725850Z","shell.execute_reply.started":"2024-03-04T03:02:10.720371Z","shell.execute_reply":"2024-03-04T03:02:10.724179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=dRatio.drop(['SeriousDlqin2yrs'],axis=1 )\ny=dRatio['SeriousDlqin2yrs']\nx.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:02:19.899891Z","iopub.execute_input":"2024-03-04T03:02:19.900304Z","iopub.status.idle":"2024-03-04T03:02:19.930678Z","shell.execute_reply.started":"2024-03-04T03:02:19.900272Z","shell.execute_reply":"2024-03-04T03:02:19.929473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x,y.values.ravel())\ny_pred= model.predict(x)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:02:26.789970Z","iopub.execute_input":"2024-03-04T03:02:26.790745Z","iopub.status.idle":"2024-03-04T03:02:37.758786Z","shell.execute_reply.started":"2024-03-04T03:02:26.790671Z","shell.execute_reply":"2024-03-04T03:02:37.757792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y,y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:02:42.570407Z","iopub.execute_input":"2024-03-04T03:02:42.570997Z","iopub.status.idle":"2024-03-04T03:02:42.592416Z","shell.execute_reply.started":"2024-03-04T03:02:42.570954Z","shell.execute_reply":"2024-03-04T03:02:42.591185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm=confusion_matrix(y,y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:03:12.869976Z","iopub.execute_input":"2024-03-04T03:03:12.870403Z","iopub.status.idle":"2024-03-04T03:03:12.900610Z","shell.execute_reply.started":"2024-03-04T03:03:12.870372Z","shell.execute_reply":"2024-03-04T03:03:12.899462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(cm,annot=True,fmt='d',cmap='Oranges',linewidths=0.5,linecolor='Black')\nplt.xticks(np.arange(2) +.5,['No def','def'])\nplt.yticks(np.arange(2) +.5,['No def','def'])\nplt.xlabel(\"predicted\")\nplt.ylabel(\"actuals\")","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:03:19.890037Z","iopub.execute_input":"2024-03-04T03:03:19.890679Z","iopub.status.idle":"2024-03-04T03:03:20.223818Z","shell.execute_reply.started":"2024-03-04T03:03:19.890629Z","shell.execute_reply":"2024-03-04T03:03:20.222397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y,y_pred))","metadata":{"execution":{"iopub.status.busy":"2024-03-04T03:03:25.650157Z","iopub.execute_input":"2024-03-04T03:03:25.650620Z","iopub.status.idle":"2024-03-04T03:03:25.887557Z","shell.execute_reply.started":"2024-03-04T03:03:25.650584Z","shell.execute_reply":"2024-03-04T03:03:25.886317Z"},"trusted":true},"execution_count":null,"outputs":[]}]}