{"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-15T00:31:17.670842Z","iopub.execute_input":"2022-07-15T00:31:17.671193Z","iopub.status.idle":"2022-07-15T00:31:17.682878Z","shell.execute_reply.started":"2022-07-15T00:31:17.671169Z","shell.execute_reply":"2022-07-15T00:31:17.681687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_feather(\"../input/amexfeather/train_data.ftr\")","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:17.684957Z","iopub.execute_input":"2022-07-15T00:31:17.686060Z","iopub.status.idle":"2022-07-15T00:31:22.748566Z","shell.execute_reply.started":"2022-07-15T00:31:17.686017Z","shell.execute_reply":"2022-07-15T00:31:22.747546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:22.750028Z","iopub.execute_input":"2022-07-15T00:31:22.750278Z","iopub.status.idle":"2022-07-15T00:31:22.779740Z","shell.execute_reply.started":"2022-07-15T00:31:22.750255Z","shell.execute_reply":"2022-07-15T00:31:22.778446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['target'].head()","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:22.781277Z","iopub.execute_input":"2022-07-15T00:31:22.781565Z","iopub.status.idle":"2022-07-15T00:31:22.789992Z","shell.execute_reply.started":"2022-07-15T00:31:22.781540Z","shell.execute_reply":"2022-07-15T00:31:22.788684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null= pd.DataFrame(data.isnull().sum(),columns=['null_count'])\nnull['percentage_of_null'] = round(((null['null_count']/len(data))*100) , 2)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:22.792432Z","iopub.execute_input":"2022-07-15T00:31:22.792949Z","iopub.status.idle":"2022-07-15T00:31:26.369039Z","shell.execute_reply.started":"2022-07-15T00:31:22.792924Z","shell.execute_reply":"2022-07-15T00:31:26.367068Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null = null.sort_values(by='percentage_of_null',ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:26.371125Z","iopub.execute_input":"2022-07-15T00:31:26.371841Z","iopub.status.idle":"2022-07-15T00:31:26.378995Z","shell.execute_reply.started":"2022-07-15T00:31:26.371801Z","shell.execute_reply":"2022-07-15T00:31:26.377262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"cleaning and eda?","metadata":{}},{"cell_type":"code","source":"null","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:26.381457Z","iopub.execute_input":"2022-07-15T00:31:26.382017Z","iopub.status.idle":"2022-07-15T00:31:26.403742Z","shell.execute_reply.started":"2022-07-15T00:31:26.381980Z","shell.execute_reply":"2022-07-15T00:31:26.402095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_binary = null.loc[null['percentage_of_null'] > 90]\nnull_binary","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:26.407348Z","iopub.execute_input":"2022-07-15T00:31:26.409133Z","iopub.status.idle":"2022-07-15T00:31:26.426770Z","shell.execute_reply.started":"2022-07-15T00:31:26.409065Z","shell.execute_reply":"2022-07-15T00:31:26.425279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## converting the above rows into binary data\nnb = []\nfor i in null_binary.T:\n    nb.append(i)\n\n# now nb has all the values we need to convert to binary data for regression","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:26.428835Z","iopub.execute_input":"2022-07-15T00:31:26.429986Z","iopub.status.idle":"2022-07-15T00:31:26.440585Z","shell.execute_reply.started":"2022-07-15T00:31:26.429950Z","shell.execute_reply":"2022-07-15T00:31:26.438463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"next step is to actually iterate through the columns in *data* and change the cols such that NULL vals are 0 and if it has a value its considered as 1. If you can do that then after try upsampling the minority class.","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in nb:\n    data[i] = data[i].fillna(0)\n    data[i] = (data[i] != 0) * 1","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:26.442541Z","iopub.execute_input":"2022-07-15T00:31:26.442844Z","iopub.status.idle":"2022-07-15T00:31:36.086003Z","shell.execute_reply.started":"2022-07-15T00:31:26.442818Z","shell.execute_reply":"2022-07-15T00:31:36.084425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"c = 0\nfor i in data[nb[0]]:\n    if i == 1:\n        c+=1\nprint(c) ## number of \"values that are not NULL\" that are now 1","metadata":{"execution":{"iopub.status.busy":"2022-07-15T00:31:36.089198Z","iopub.execute_input":"2022-07-15T00:31:36.089595Z","iopub.status.idle":"2022-07-15T00:31:37.443053Z","shell.execute_reply.started":"2022-07-15T00:31:36.089564Z","shell.execute_reply":"2022-07-15T00:31:37.440612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}