{"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":"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-07-18T18:15:39.506603Z","iopub.execute_input":"2022-07-18T18:15:39.507197Z","iopub.status.idle":"2022-07-18T18:15:39.544924Z","shell.execute_reply.started":"2022-07-18T18:15:39.507030Z","shell.execute_reply":"2022-07-18T18:15:39.543453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_feather('../input/parquet-files-amexdefault-prediction/train_data.ftr')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:15:42.613086Z","iopub.execute_input":"2022-07-18T18:15:42.613554Z","iopub.status.idle":"2022-07-18T18:16:03.511374Z","shell.execute_reply.started":"2022-07-18T18:15:42.613523Z","shell.execute_reply":"2022-07-18T18:16:03.509984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = pd.read_csv('../input/amex-default-prediction/train_labels.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:16:07.443974Z","iopub.execute_input":"2022-07-18T18:16:07.444491Z","iopub.status.idle":"2022-07-18T18:16:08.263961Z","shell.execute_reply.started":"2022-07-18T18:16:07.444461Z","shell.execute_reply":"2022-07-18T18:16:08.262666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cd = pd.merge(train_df, train_labels, how='inner')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:16:08.267253Z","iopub.execute_input":"2022-07-18T18:16:08.267598Z","iopub.status.idle":"2022-07-18T18:17:36.693571Z","shell.execute_reply.started":"2022-07-18T18:16:08.267568Z","shell.execute_reply":"2022-07-18T18:17:36.692156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_nan_cols(df, nan_percent=0.8):\n    threshold = len(df.index) * nan_percent\n    return [c for c in df.columns if sum(df[c].isnull()) >= threshold]  ","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:17:52.835682Z","iopub.execute_input":"2022-07-18T18:17:52.836118Z","iopub.status.idle":"2022-07-18T18:17:52.847278Z","shell.execute_reply.started":"2022-07-18T18:17:52.836071Z","shell.execute_reply":"2022-07-18T18:17:52.843428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nan_cols = get_nan_cols(df_cd,0.8)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:21:44.887766Z","iopub.execute_input":"2022-07-18T18:21:44.888245Z","iopub.status.idle":"2022-07-18T18:24:10.043951Z","shell.execute_reply.started":"2022-07-18T18:21:44.888211Z","shell.execute_reply":"2022-07-18T18:24:10.042636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cd = df_cd.drop(columns = nan_cols,axis=1)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:24:42.238491Z","iopub.execute_input":"2022-07-18T18:24:42.238888Z","iopub.status.idle":"2022-07-18T18:24:47.086374Z","shell.execute_reply.started":"2022-07-18T18:24:42.238857Z","shell.execute_reply":"2022-07-18T18:24:47.081269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = df_cd.columns\nnum_cols = df_cd._get_numeric_data().columns\n\ncat_cols = list(set(cols)-set(num_cols))\nprint(cat_cols)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:26:13.505312Z","iopub.execute_input":"2022-07-18T18:26:13.505766Z","iopub.status.idle":"2022-07-18T18:26:13.514972Z","shell.execute_reply.started":"2022-07-18T18:26:13.505732Z","shell.execute_reply":"2022-07-18T18:26:13.513043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.impute import SimpleImputer\nfrom sklearn import model_selection\n\nimputer = SimpleImputer(missing_values=np.nan, strategy='most_frequent')","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:26:45.190155Z","iopub.execute_input":"2022-07-18T18:26:45.190594Z","iopub.status.idle":"2022-07-18T18:26:46.334236Z","shell.execute_reply.started":"2022-07-18T18:26:45.190563Z","shell.execute_reply":"2022-07-18T18:26:46.333003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filtered_cat_cols = list(set(df_cd[cat_cols]) - {'S_2','customer_ID'})\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:28:12.665514Z","iopub.execute_input":"2022-07-18T18:28:12.665954Z","iopub.status.idle":"2022-07-18T18:28:12.796252Z","shell.execute_reply.started":"2022-07-18T18:28:12.665921Z","shell.execute_reply":"2022-07-18T18:28:12.794910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_cd[filtered_cat_cols] = imputer.fit_transform(df_cd[filtered_cat_cols])\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:28:39.295462Z","iopub.execute_input":"2022-07-18T18:28:39.295908Z","iopub.status.idle":"2022-07-18T18:29:08.128200Z","shell.execute_reply.started":"2022-07-18T18:28:39.295876Z","shell.execute_reply":"2022-07-18T18:29:08.126911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"numeric_cols = df_cd.select_dtypes(np.number).columns\n# print('Numerical columns in raw training data', '\\n',numeric_cols)","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:29:37.109573Z","iopub.execute_input":"2022-07-18T18:29:37.109960Z","iopub.status.idle":"2022-07-18T18:29:42.358160Z","shell.execute_reply.started":"2022-07-18T18:29:37.109928Z","shell.execute_reply":"2022-07-18T18:29:42.356855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"k = SimpleImputer(missing_values=np.nan, strategy='mean')\ndf_cd[numeric_cols] = k.fit_transform(df_cd[numeric_cols])\n\n\n# df_cd.loc[:,numeric_cols].fillna(df_cd[numeric_cols].mean(),inplace = True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:39:36.589602Z","iopub.execute_input":"2022-07-18T18:39:36.590114Z"},"trusted":true},"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":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:14:50.789793Z","iopub.status.idle":"2022-07-18T18:14:50.790750Z","shell.execute_reply.started":"2022-07-18T18:14:50.790452Z","shell.execute_reply":"2022-07-18T18:14:50.790481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2022-07-18T18:14:50.792546Z","iopub.status.idle":"2022-07-18T18:14:50.793501Z","shell.execute_reply.started":"2022-07-18T18:14:50.793183Z","shell.execute_reply":"2022-07-18T18:14:50.793213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n    \n\n\n","metadata":{},"execution_count":null,"outputs":[]}]}