{"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":50160,"databundleVersionId":7921029,"sourceType":"competition"}],"dockerImageVersionId":30698,"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\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-05-25T09:49:24.470368Z","iopub.execute_input":"2024-05-25T09:49:24.470762Z","iopub.status.idle":"2024-05-25T09:49:24.899841Z","shell.execute_reply.started":"2024-05-25T09:49:24.470731Z","shell.execute_reply":"2024-05-25T09:49:24.898859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_feature_def = pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/feature_definitions.csv')\ndf_subm = pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:24.902011Z","iopub.execute_input":"2024-05-25T09:49:24.902609Z","iopub.status.idle":"2024-05-25T09:49:24.924757Z","shell.execute_reply.started":"2024-05-25T09:49:24.902569Z","shell.execute_reply":"2024-05-25T09:49:24.923594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_feature_def","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:25.137249Z","iopub.execute_input":"2024-05-25T09:49:25.137989Z","iopub.status.idle":"2024-05-25T09:49:25.162858Z","shell.execute_reply.started":"2024-05-25T09:49:25.137954Z","shell.execute_reply":"2024-05-25T09:49:25.161858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_subm","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:25.416268Z","iopub.execute_input":"2024-05-25T09:49:25.417187Z","iopub.status.idle":"2024-05-25T09:49:25.428356Z","shell.execute_reply.started":"2024-05-25T09:49:25.417134Z","shell.execute_reply":"2024-05-25T09:49:25.427269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/train_base.csv')\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:25.674349Z","iopub.execute_input":"2024-05-25T09:49:25.675348Z","iopub.status.idle":"2024-05-25T09:49:26.791896Z","shell.execute_reply.started":"2024-05-25T09:49:25.675317Z","shell.execute_reply":"2024-05-25T09:49:26.790872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = '/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/'\ndf_train=[]\nfor file in os.listdir(train_path):\n    #df_train_temp = pd.read_csv(train_path+file)\n    print(file)\n    #print(df_train_temp.columns,len(df_train_temp.columns))\ndf_train_base = pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/train_base.csv')\ndf_test_base = pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/csv_files/test/test_base.csv')\ndf_train_applprev_1_0 =pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/csv_files/train/train_applprev_1_0.csv')\ndf_test_applprev_1_0 =pd.read_csv('/kaggle/input/home-credit-credit-risk-model-stability/csv_files/test/test_applprev_1_0.csv')","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:26.793635Z","iopub.execute_input":"2024-05-25T09:49:26.79393Z","iopub.status.idle":"2024-05-25T09:49:56.168393Z","shell.execute_reply.started":"2024-05-25T09:49:26.793905Z","shell.execute_reply":"2024-05-25T09:49:56.167476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_base.info()\ndf_test_base.info()\ndf_train_applprev_1_0.info()\ndf_test_applprev_1_0.info()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:56.169754Z","iopub.execute_input":"2024-05-25T09:49:56.170172Z","iopub.status.idle":"2024-05-25T09:49:56.286004Z","shell.execute_reply.started":"2024-05-25T09:49:56.170124Z","shell.execute_reply":"2024-05-25T09:49:56.284939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### checking the unique values of column 27\nprint(df_train_applprev_1_0.iloc[0:,27].unique())\nprint(df_test_applprev_1_0.iloc[0:,27].unique())\n\n### finding out if any of the column is all null \nprint(df_train_applprev_1_0.isnull().all())\nprint(df_test_applprev_1_0.isnull().all())\n\n","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:56.288227Z","iopub.execute_input":"2024-05-25T09:49:56.288559Z","iopub.status.idle":"2024-05-25T09:49:59.849727Z","shell.execute_reply.started":"2024-05-25T09:49:56.288531Z","shell.execute_reply":"2024-05-25T09:49:59.848693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### count of applprev_1_0 after dropping null\nprint(df_train_applprev_1_0.describe())\nprint(df_train_applprev_1_0.dropna().describe())\n","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:49:59.850824Z","iopub.execute_input":"2024-05-25T09:49:59.851129Z","iopub.status.idle":"2024-05-25T09:50:07.445637Z","shell.execute_reply.started":"2024-05-25T09:49:59.851095Z","shell.execute_reply":"2024-05-25T09:50:07.44455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### count of applprev_1_0 after dropping null\nprint(df_test_applprev_1_0.describe())\nprint(df_test_applprev_1_0.dropna().describe())\n","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:07.44729Z","iopub.execute_input":"2024-05-25T09:50:07.44769Z","iopub.status.idle":"2024-05-25T09:50:07.541245Z","shell.execute_reply.started":"2024-05-25T09:50:07.447655Z","shell.execute_reply":"2024-05-25T09:50:07.540265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_columns = set(df_test_applprev_1_0.dropna().columns)\ndf_train_columns = set(df_train_applprev_1_0.dropna().columns)","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:07.542587Z","iopub.execute_input":"2024-05-25T09:50:07.542886Z","iopub.status.idle":"2024-05-25T09:50:11.081558Z","shell.execute_reply.started":"2024-05-25T09:50:07.542862Z","shell.execute_reply":"2024-05-25T09:50:11.080464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(df_train_applprev_1_0.columns),len(df_test_applprev_1_0.columns))\nlen(df_train_columns),len(df_test_columns)","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:11.082979Z","iopub.execute_input":"2024-05-25T09:50:11.083317Z","iopub.status.idle":"2024-05-25T09:50:11.090835Z","shell.execute_reply.started":"2024-05-25T09:50:11.083289Z","shell.execute_reply":"2024-05-25T09:50:11.089825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin = df_train_base.join(df_train_applprev_1_0.set_index('case_id'),\n                                  on='case_id',how='inner')","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:11.092122Z","iopub.execute_input":"2024-05-25T09:50:11.092475Z","iopub.status.idle":"2024-05-25T09:50:17.04933Z","shell.execute_reply.started":"2024-05-25T09:50:11.092446Z","shell.execute_reply":"2024-05-25T09:50:17.048242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:17.053466Z","iopub.execute_input":"2024-05-25T09:50:17.053841Z","iopub.status.idle":"2024-05-25T09:50:19.998005Z","shell.execute_reply.started":"2024-05-25T09:50:17.053811Z","shell.execute_reply":"2024-05-25T09:50:19.996952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin.dropna()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:19.999215Z","iopub.execute_input":"2024-05-25T09:50:19.999503Z","iopub.status.idle":"2024-05-25T09:50:23.775677Z","shell.execute_reply.started":"2024-05-25T09:50:19.999479Z","shell.execute_reply":"2024-05-25T09:50:23.774519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" df_train_fin[df_train_fin['case_id'] == 2]","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:23.776988Z","iopub.execute_input":"2024-05-25T09:50:23.777333Z","iopub.status.idle":"2024-05-25T09:50:23.803851Z","shell.execute_reply.started":"2024-05-25T09:50:23.777303Z","shell.execute_reply":"2024-05-25T09:50:23.802872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test_applprev_1_0","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:23.805091Z","iopub.execute_input":"2024-05-25T09:50:23.805454Z","iopub.status.idle":"2024-05-25T09:50:23.834318Z","shell.execute_reply.started":"2024-05-25T09:50:23.805396Z","shell.execute_reply":"2024-05-25T09:50:23.833119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_train_fin.case_id.unique()) , len(df_train_base.case_id.unique())","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:23.8356Z","iopub.execute_input":"2024-05-25T09:50:23.835891Z","iopub.status.idle":"2024-05-25T09:50:23.94175Z","shell.execute_reply.started":"2024-05-25T09:50:23.835866Z","shell.execute_reply":"2024-05-25T09:50:23.940719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin.fillna(value = 0,inplace = True) ### filling 0 as NULL values","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:23.94316Z","iopub.execute_input":"2024-05-25T09:50:23.944017Z","iopub.status.idle":"2024-05-25T09:50:34.778117Z","shell.execute_reply.started":"2024-05-25T09:50:23.943981Z","shell.execute_reply":"2024-05-25T09:50:34.776727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin.info()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:34.779428Z","iopub.execute_input":"2024-05-25T09:50:34.779718Z","iopub.status.idle":"2024-05-25T09:50:34.792123Z","shell.execute_reply.started":"2024-05-25T09:50:34.779692Z","shell.execute_reply":"2024-05-25T09:50:34.790884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin.describe()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:34.793671Z","iopub.execute_input":"2024-05-25T09:50:34.794058Z","iopub.status.idle":"2024-05-25T09:50:37.814876Z","shell.execute_reply.started":"2024-05-25T09:50:34.794023Z","shell.execute_reply":"2024-05-25T09:50:37.813684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:37.816157Z","iopub.execute_input":"2024-05-25T09:50:37.816527Z","iopub.status.idle":"2024-05-25T09:50:40.74071Z","shell.execute_reply.started":"2024-05-25T09:50:37.816498Z","shell.execute_reply":"2024-05-25T09:50:40.739665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data_types = df_train_fin.dtypes\nfor col in df_train_fin.columns:\n    print(str(df_train_fin[col].dtypes))\ndf_train_fin['approvaldate_319D'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T10:22:52.708435Z","iopub.execute_input":"2024-05-25T10:22:52.709883Z","iopub.status.idle":"2024-05-25T10:22:52.987793Z","shell.execute_reply.started":"2024-05-25T10:22:52.709835Z","shell.execute_reply":"2024-05-25T10:22:52.98604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_fin_temp = df_train_fin[df_train_fin['approvaldate_319D'] != 0]\nprint(df_train_fin_temp['approvaldate_319D'].unique())\ndf_train_fin_2019= df_train_fin_temp[df_train_fin_temp['approvaldate_319D'].str.split('-').str[0] == '2019']","metadata":{"execution":{"iopub.status.busy":"2024-05-25T10:35:39.657953Z","iopub.execute_input":"2024-05-25T10:35:39.658732Z","iopub.status.idle":"2024-05-25T10:35:46.288444Z","shell.execute_reply.started":"2024-05-25T10:35:39.6587Z","shell.execute_reply":"2024-05-25T10:35:46.287303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n\nsns.barplot(df_train_fin_2019,\n            x=\"approvaldate_319D\", y=\"target\")","metadata":{"execution":{"iopub.status.busy":"2024-05-25T10:48:34.846491Z","iopub.execute_input":"2024-05-25T10:48:34.847254Z","iopub.status.idle":"2024-05-25T10:48:48.535846Z","shell.execute_reply.started":"2024-05-25T10:48:34.847219Z","shell.execute_reply":"2024-05-25T10:48:48.5345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(1,13):\n    plt.figure(figsize =(12,6))\n    sns.barplot(df_train_fin_2019[df_train_fin_2019['approvaldate_319D'].str.split('-').str[2] == str(i).zfill(2) ],\n            x=\"approvaldate_319D\", y=\"target\",orient= 'v')\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-25T10:52:14.406684Z","iopub.execute_input":"2024-05-25T10:52:14.40707Z","iopub.status.idle":"2024-05-25T10:52:31.654081Z","shell.execute_reply.started":"2024-05-25T10:52:14.407033Z","shell.execute_reply":"2024-05-25T10:52:31.652928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns = []\nfor col in df_train_fin.columns:\n    if col !='target' and str(df_train_fin[col].dtypes) != 'object':\n        columns.append(col)","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:40.750656Z","iopub.execute_input":"2024-05-25T09:50:40.751022Z","iopub.status.idle":"2024-05-25T09:50:40.763275Z","shell.execute_reply.started":"2024-05-25T09:50:40.750994Z","shell.execute_reply":"2024-05-25T09:50:40.761867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X= df_train1_","metadata":{"execution":{"iopub.status.busy":"2024-05-25T09:50:40.764601Z","iopub.execute_input":"2024-05-25T09:50:40.764953Z","iopub.status.idle":"2024-05-25T09:50:40.775571Z","shell.execute_reply.started":"2024-05-25T09:50:40.764916Z","shell.execute_reply":"2024-05-25T09:50:40.774447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}