{"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":"# Overview\nThis is a very quick exploration of the problem end-to-end. \n\nIn this work, we have reviewed the datasets and tested our baseline model on the subset of the data. \n\n* Initial thoughts:\n\n    1. Need to handle large amount of input data - try using chunks like we do use batches in deep learning\n    2. Need to handle datatypes of the data - handle categorical columns\n    3. Need to handle the missing values. - Understand is missing leads to any signal. \n    4. Train various models and evaluate on validation dataset.- Ensembels , Fastai \n    5. Finally make predictions on test set to submit","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-11-26T17:22:50.803574Z","iopub.execute_input":"2022-11-26T17:22:50.804555Z","iopub.status.idle":"2022-11-26T17:22:50.813162Z","shell.execute_reply.started":"2022-11-26T17:22:50.804515Z","shell.execute_reply":"2022-11-26T17:22:50.812044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai import *","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:22:50.814494Z","iopub.execute_input":"2022-11-26T17:22:50.814921Z","iopub.status.idle":"2022-11-26T17:22:50.822293Z","shell.execute_reply.started":"2022-11-26T17:22:50.814889Z","shell.execute_reply":"2022-11-26T17:22:50.821114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sub_path = \"/kaggle/input/amex-default-prediction/sample_submission.csv\"\ndf_train_path = \"/kaggle/input/amex-default-prediction/train_data.csv\"\ndf_test_path = \"/kaggle/input/amex-default-prediction/test_data.csv\"\ndf_labels_path = \"/kaggle/input/amex-default-prediction/train_labels.csv\"","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:22:52.000839Z","iopub.execute_input":"2022-11-26T17:22:52.001241Z","iopub.status.idle":"2022-11-26T17:22:52.007423Z","shell.execute_reply.started":"2022-11-26T17:22:52.001193Z","shell.execute_reply":"2022-11-26T17:22:52.005503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_size = 10000\nbatch_size = 200\n\ntrain_reader = pd.read_csv(df_train_path, dtype=str, chunksize=batch_size)\nlabels_reader = pd.read_csv(df_labels_path, dtype=str, chunksize=batch_size)\ntest_reader = pd.read_csv(df_test_path, dtype=str, chunksize=batch_size)\n\n# df_train = pd.read_csv(df_train_path).sample(n_samples, random_state=44)\n# df_labels = pd.read_csv(df_labels_path).sample(n_samples, random_state=44)\n# df_test = pd.read_csv(df_test_path).sample(n_samples, random_state=44)\n# df_sub = pd.read_csv(df_sub_path).sample(n_samples, random_state=44)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:34:35.769186Z","iopub.execute_input":"2022-11-26T17:34:35.770042Z","iopub.status.idle":"2022-11-26T17:34:35.787384Z","shell.execute_reply.started":"2022-11-26T17:34:35.770001Z","shell.execute_reply":"2022-11-26T17:34:35.786289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = train_reader.get_chunk(sample_size)\ndf_labels = labels_reader.get_chunk(sample_size)\ndf_test = test_reader.get_chunk(sample_size)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:34:37.549545Z","iopub.execute_input":"2022-11-26T17:34:37.549950Z","iopub.status.idle":"2022-11-26T17:34:39.863012Z","shell.execute_reply.started":"2022-11-26T17:34:37.549919Z","shell.execute_reply":"2022-11-26T17:34:39.861804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:34:45.911154Z","iopub.execute_input":"2022-11-26T17:34:45.911572Z","iopub.status.idle":"2022-11-26T17:34:45.937239Z","shell.execute_reply.started":"2022-11-26T17:34:45.911538Z","shell.execute_reply":"2022-11-26T17:34:45.935798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_labels.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:34:55.788753Z","iopub.execute_input":"2022-11-26T17:34:55.789195Z","iopub.status.idle":"2022-11-26T17:34:55.800718Z","shell.execute_reply.started":"2022-11-26T17:34:55.789159Z","shell.execute_reply":"2022-11-26T17:34:55.799242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-26T17:35:09.567908Z","iopub.execute_input":"2022-11-26T17:35:09.568310Z","iopub.status.idle":"2022-11-26T17:35:09.594705Z","shell.execute_reply.started":"2022-11-26T17:35:09.568277Z","shell.execute_reply":"2022-11-26T17:35:09.593547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_Xy = pd.merge(df_train, df_labels, on='customer_ID')","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:01:02.368538Z","iopub.execute_input":"2022-11-26T18:01:02.369848Z","iopub.status.idle":"2022-11-26T18:01:02.411023Z","shell.execute_reply.started":"2022-11-26T18:01:02.369792Z","shell.execute_reply":"2022-11-26T18:01:02.409921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_Xy = df_train_Xy.drop(columns=['S_2'])","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:01:03.950614Z","iopub.execute_input":"2022-11-26T18:01:03.951057Z","iopub.status.idle":"2022-11-26T18:01:04.065683Z","shell.execute_reply.started":"2022-11-26T18:01:03.951023Z","shell.execute_reply":"2022-11-26T18:01:04.064139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical_cols = ['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_63', 'D_64', 'D_66', 'D_68','target']","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:01:04.946200Z","iopub.execute_input":"2022-11-26T18:01:04.946854Z","iopub.status.idle":"2022-11-26T18:01:04.951982Z","shell.execute_reply.started":"2022-11-26T18:01:04.946819Z","shell.execute_reply":"2022-11-26T18:01:04.950732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_cols = list(df_train_Xy.columns)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:01:11.131791Z","iopub.execute_input":"2022-11-26T18:01:11.132619Z","iopub.status.idle":"2022-11-26T18:01:11.138171Z","shell.execute_reply.started":"2022-11-26T18:01:11.132555Z","shell.execute_reply":"2022-11-26T18:01:11.136575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cont_cols = list(set(all_cols)-set(categorical_cols))\ncont_cols = cont_cols[:5] + ['target']","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:03:07.820168Z","iopub.execute_input":"2022-11-26T18:03:07.821059Z","iopub.status.idle":"2022-11-26T18:03:07.825064Z","shell.execute_reply.started":"2022-11-26T18:03:07.821025Z","shell.execute_reply":"2022-11-26T18:03:07.824299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cont_cols","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:03:08.845274Z","iopub.execute_input":"2022-11-26T18:03:08.846745Z","iopub.status.idle":"2022-11-26T18:03:08.853031Z","shell.execute_reply.started":"2022-11-26T18:03:08.846692Z","shell.execute_reply":"2022-11-26T18:03:08.852181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_Xy = df_train_Xy[cont_cols]","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:03:13.462896Z","iopub.execute_input":"2022-11-26T18:03:13.463476Z","iopub.status.idle":"2022-11-26T18:03:13.482753Z","shell.execute_reply.started":"2022-11-26T18:03:13.463443Z","shell.execute_reply":"2022-11-26T18:03:13.481215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_Xy['target'] = df_train_Xy['target'].astype('category')","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:01:49.647069Z","iopub.execute_input":"2022-11-26T18:01:49.647479Z","iopub.status.idle":"2022-11-26T18:01:49.685349Z","shell.execute_reply.started":"2022-11-26T18:01:49.647446Z","shell.execute_reply":"2022-11-26T18:01:49.684004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X,y = df_train_Xy.iloc[:,:-1], df_train_Xy.iloc[:,-1]","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:07:48.143128Z","iopub.execute_input":"2022-11-26T18:07:48.143536Z","iopub.status.idle":"2022-11-26T18:07:48.151409Z","shell.execute_reply.started":"2022-11-26T18:07:48.143506Z","shell.execute_reply":"2022-11-26T18:07:48.150253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:07:49.834733Z","iopub.execute_input":"2022-11-26T18:07:49.835941Z","iopub.status.idle":"2022-11-26T18:07:49.849776Z","shell.execute_reply.started":"2022-11-26T18:07:49.835874Z","shell.execute_reply":"2022-11-26T18:07:49.848625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:07:50.770579Z","iopub.execute_input":"2022-11-26T18:07:50.771038Z","iopub.status.idle":"2022-11-26T18:07:50.781099Z","shell.execute_reply.started":"2022-11-26T18:07:50.770983Z","shell.execute_reply":"2022-11-26T18:07:50.779743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = X.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:07:52.844274Z","iopub.execute_input":"2022-11-26T18:07:52.844703Z","iopub.status.idle":"2022-11-26T18:07:52.853521Z","shell.execute_reply.started":"2022-11-26T18:07:52.844660Z","shell.execute_reply":"2022-11-26T18:07:52.852196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:09:20.606621Z","iopub.execute_input":"2022-11-26T18:09:20.607003Z","iopub.status.idle":"2022-11-26T18:09:20.617603Z","shell.execute_reply.started":"2022-11-26T18:09:20.606974Z","shell.execute_reply":"2022-11-26T18:09:20.616399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:09:21.797400Z","iopub.execute_input":"2022-11-26T18:09:21.798092Z","iopub.status.idle":"2022-11-26T18:09:21.802808Z","shell.execute_reply.started":"2022-11-26T18:09:21.798055Z","shell.execute_reply":"2022-11-26T18:09:21.801478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf = RandomForestClassifier(n_estimators=5, max_depth=2, random_state=0)\nclf.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:09:35.295110Z","iopub.execute_input":"2022-11-26T18:09:35.295911Z","iopub.status.idle":"2022-11-26T18:09:35.351537Z","shell.execute_reply.started":"2022-11-26T18:09:35.295863Z","shell.execute_reply":"2022-11-26T18:09:35.350372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.score(X_test, y_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:10:31.521406Z","iopub.execute_input":"2022-11-26T18:10:31.521850Z","iopub.status.idle":"2022-11-26T18:10:31.541732Z","shell.execute_reply.started":"2022-11-26T18:10:31.521813Z","shell.execute_reply":"2022-11-26T18:10:31.540535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:10:38.295505Z","iopub.execute_input":"2022-11-26T18:10:38.295909Z","iopub.status.idle":"2022-11-26T18:10:38.309638Z","shell.execute_reply.started":"2022-11-26T18:10:38.295880Z","shell.execute_reply":"2022-11-26T18:10:38.308303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = df_test[cont_cols[:5]].fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:10:39.127956Z","iopub.execute_input":"2022-11-26T18:10:39.128677Z","iopub.status.idle":"2022-11-26T18:10:39.139355Z","shell.execute_reply.started":"2022-11-26T18:10:39.128627Z","shell.execute_reply":"2022-11-26T18:10:39.137890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.predict(df_test)","metadata":{"execution":{"iopub.status.busy":"2022-11-26T18:10:46.937198Z","iopub.execute_input":"2022-11-26T18:10:46.937625Z","iopub.status.idle":"2022-11-26T18:10:46.968449Z","shell.execute_reply.started":"2022-11-26T18:10:46.937589Z","shell.execute_reply":"2022-11-26T18:10:46.967160Z"},"trusted":true},"execution_count":null,"outputs":[]}]}