{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# AMEX - Aggregated Dataset\n## Predict if a customer will default in the future...\n\nThe objective of this competition is to predict the probability that a customer does not pay back their credit card balance amount in the future based on their monthly customer profile. The target binary variable is calculated by observing 18 months performance window after the latest credit card statement, and if the customer does not pay due amount in 120 days after their latest statement date it is considered a default event.\n\n\n\n\n\n\n\n#### Resources\nhttps://www.kaggle.com/code/huseyincot/amex-agg-data-how-it-created","metadata":{}},{"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":"2022-05-29T18:06:16.739587Z","iopub.execute_input":"2022-05-29T18:06:16.740203Z","iopub.status.idle":"2022-05-29T18:06:16.816070Z","shell.execute_reply.started":"2022-05-29T18:06:16.740004Z","shell.execute_reply":"2022-05-29T18:06:16.815276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# I like to disable my Notebook Warnings.\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:06:16.819355Z","iopub.execute_input":"2022-05-29T18:06:16.819861Z","iopub.status.idle":"2022-05-29T18:06:16.827540Z","shell.execute_reply.started":"2022-05-29T18:06:16.819824Z","shell.execute_reply":"2022-05-29T18:06:16.826510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Notebook Configuration...\n\n# Amount of data we want to load into the Model...\nDATA_ROWS = None\n# Dataframe, the amount of rows and cols to visualize...\nNROWS = 50\nNCOLS = 15\n# Main data location path...\nBASE_PATH = '...'","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:06:16.829011Z","iopub.execute_input":"2022-05-29T18:06:16.829837Z","iopub.status.idle":"2022-05-29T18:06:16.842424Z","shell.execute_reply.started":"2022-05-29T18:06:16.829799Z","shell.execute_reply":"2022-05-29T18:06:16.841306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Configure notebook display settings to only use 2 decimal places, tables look nicer.\npd.options.display.float_format = '{:,.5f}'.format\npd.set_option('display.max_columns', NCOLS) \npd.set_option('display.max_rows', NROWS)","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:06:16.844105Z","iopub.execute_input":"2022-05-29T18:06:16.845220Z","iopub.status.idle":"2022-05-29T18:06:16.861443Z","shell.execute_reply.started":"2022-05-29T18:06:16.845173Z","shell.execute_reply":"2022-05-29T18:06:16.860313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"%%time\n# Load the CSV information into a Pandas DataFrame...\ntrn_data = pd.read_feather('../input/parquet-files-amexdefault-prediction/train_data.ftr')\ntrn_lbls = pd.read_csv('/kaggle/input/amex-default-prediction/train_labels.csv').set_index('customer_ID')\n\ntst_data = pd.read_feather('../input/parquet-files-amexdefault-prediction/test_data.ftr')","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:06:16.863952Z","iopub.execute_input":"2022-05-29T18:06:16.864355Z","iopub.status.idle":"2022-05-29T18:07:10.547919Z","shell.execute_reply.started":"2022-05-29T18:06:16.864319Z","shell.execute_reply":"2022-05-29T18:07:10.546749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv('/kaggle/input/amex-default-prediction/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:10.549352Z","iopub.execute_input":"2022-05-29T18:07:10.549730Z","iopub.status.idle":"2022-05-29T18:07:12.672535Z","shell.execute_reply.started":"2022-05-29T18:07:10.549699Z","shell.execute_reply":"2022-05-29T18:07:12.671482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"%%time\n# Explore the shape of the DataFrame...\ntrn_data.shape","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:12.673844Z","iopub.execute_input":"2022-05-29T18:07:12.674254Z","iopub.status.idle":"2022-05-29T18:07:12.685732Z","shell.execute_reply.started":"2022-05-29T18:07:12.674222Z","shell.execute_reply":"2022-05-29T18:07:12.684769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display simple information of the variables in the dataset...\ntrn_data.info()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:12.687195Z","iopub.execute_input":"2022-05-29T18:07:12.687803Z","iopub.status.idle":"2022-05-29T18:07:12.733579Z","shell.execute_reply.started":"2022-05-29T18:07:12.687750Z","shell.execute_reply":"2022-05-29T18:07:12.732468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display the first few rows of the DataFrame...\ntrn_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:12.734873Z","iopub.execute_input":"2022-05-29T18:07:12.735205Z","iopub.status.idle":"2022-05-29T18:07:12.765997Z","shell.execute_reply.started":"2022-05-29T18:07:12.735176Z","shell.execute_reply":"2022-05-29T18:07:12.765050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"%%time\n# Display the Min Date...\ntrn_data['S_2'].min()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:12.767365Z","iopub.execute_input":"2022-05-29T18:07:12.767687Z","iopub.status.idle":"2022-05-29T18:07:13.617108Z","shell.execute_reply.started":"2022-05-29T18:07:12.767659Z","shell.execute_reply":"2022-05-29T18:07:13.616035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display the Max Date...\ntrn_data['S_2'].max()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:13.618362Z","iopub.execute_input":"2022-05-29T18:07:13.618685Z","iopub.status.idle":"2022-05-29T18:07:14.457814Z","shell.execute_reply.started":"2022-05-29T18:07:13.618657Z","shell.execute_reply":"2022-05-29T18:07:14.456763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Generate a simple statistical summary of the DataFrame, Only Numerical...\ntrn_data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:07:14.458957Z","iopub.execute_input":"2022-05-29T18:07:14.459312Z","iopub.status.idle":"2022-05-29T18:10:00.622339Z","shell.execute_reply.started":"2022-05-29T18:07:14.459281Z","shell.execute_reply":"2022-05-29T18:10:00.621142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Calculates the total number of missing values...\ntrn_data.isnull().sum().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:10:00.625235Z","iopub.execute_input":"2022-05-29T18:10:00.625613Z","iopub.status.idle":"2022-05-29T18:10:07.472604Z","shell.execute_reply.started":"2022-05-29T18:10:00.625582Z","shell.execute_reply":"2022-05-29T18:10:07.471456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display the number of missing values by variable...\ntrn_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:10:07.474290Z","iopub.execute_input":"2022-05-29T18:10:07.474651Z","iopub.status.idle":"2022-05-29T18:10:13.599180Z","shell.execute_reply.started":"2022-05-29T18:10:07.474621Z","shell.execute_reply":"2022-05-29T18:10:13.598113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\n# Display the number of unique values for each variable...\ntrn_data.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:10:13.600752Z","iopub.execute_input":"2022-05-29T18:10:13.601077Z","iopub.status.idle":"2022-05-29T18:10:33.089709Z","shell.execute_reply.started":"2022-05-29T18:10:13.601049Z","shell.execute_reply":"2022-05-29T18:10:33.088546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Based on the dataset Descriptions this are Categorical Variables...\ncateg_variables = ['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_63', 'D_64', 'D_66', 'D_68']","metadata":{"execution":{"iopub.status.busy":"2022-05-29T18:20:18.744475Z","iopub.execute_input":"2022-05-29T18:20:18.745117Z","iopub.status.idle":"2022-05-29T18:20:18.752510Z","shell.execute_reply.started":"2022-05-29T18:20:18.745062Z","shell.execute_reply":"2022-05-29T18:20:18.751527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Based on the number of unique values this are ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}