{"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-06-05T16:17:46.309954Z","iopub.execute_input":"2022-06-05T16:17:46.310591Z","iopub.status.idle":"2022-06-05T16:17:46.344051Z","shell.execute_reply.started":"2022-06-05T16:17:46.310472Z","shell.execute_reply":"2022-06-05T16:17:46.342905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# LOAD LIBRARIES\nimport pandas as pd, numpy as np # CPU libraries\nimport cupy, cudf # GPU libraries\nimport matplotlib.pyplot as plt, gc, os\n\nprint('RAPIDS version',cudf.__version__)","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:17:46.34597Z","iopub.execute_input":"2022-06-05T16:17:46.346508Z","iopub.status.idle":"2022-06-05T16:17:50.827304Z","shell.execute_reply.started":"2022-06-05T16:17:46.346462Z","shell.execute_reply":"2022-06-05T16:17:50.826463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import fastai","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:17:50.829341Z","iopub.execute_input":"2022-06-05T16:17:50.829728Z","iopub.status.idle":"2022-06-05T16:17:50.836686Z","shell.execute_reply.started":"2022-06-05T16:17:50.829688Z","shell.execute_reply":"2022-06-05T16:17:50.83559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier\nfrom pandas.api.types import is_string_dtype, is_numeric_dtype, is_categorical_dtype\nfrom fastai.tabular.all import *\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.tree import DecisionTreeRegressor\n#from dtreeviz.trees import *\nfrom IPython.display import Image, display_svg, SVG\nfrom sklearn import preprocessing\nimport gc\nimport random\npd.options.display.max_rows = 20\npd.options.display.max_columns = 8","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:17:50.84131Z","iopub.execute_input":"2022-06-05T16:17:50.842399Z","iopub.status.idle":"2022-06-05T16:17:52.646193Z","shell.execute_reply.started":"2022-06-05T16:17:50.842359Z","shell.execute_reply":"2022-06-05T16:17:52.645353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# VERSION NAME FOR SAVED MODEL FILES\nVER = 1\n\n# TRAIN RANDOM SEED\nSEED = 42\n\n# FILL NAN VALUE\nNAN_VALUE = -127 # will fit in int8\n\n# FOLDS PER MODEL\nFOLDS = 5","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:17:52.648336Z","iopub.execute_input":"2022-06-05T16:17:52.650154Z","iopub.status.idle":"2022-06-05T16:17:52.658421Z","shell.execute_reply.started":"2022-06-05T16:17:52.650108Z","shell.execute_reply":"2022-06-05T16:17:52.6576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_file(path = '', usecols = None):\n    # LOAD DATAFRAME\n    if usecols is not None: df = cudf.read_parquet(path, columns=usecols)\n    else: df = cudf.read_parquet(path)\n    # REDUCE DTYPE FOR CUSTOMER AND DATE\n    df['customer_ID'] = df['customer_ID'].str[-16:].str.hex_to_int().astype('int64')\n    df.S_2 = cudf.to_datetime( df.S_2 )\n    # SORT BY CUSTOMER AND DATE (so agg('last') works correctly)\n    #df = df.sort_values(['customer_ID','S_2'])\n    #df = df.reset_index(drop=True)\n    # FILL NAN\n    df = df.fillna(NAN_VALUE) \n    print('shape of data:', df.shape)\n    \n    return df\n\nprint('Reading train data...')\nTRAIN_PATH = '../input/amex-data-integer-dtypes-parquet-format/train.parquet'\ntrain = read_file(path = TRAIN_PATH)","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:17:52.661295Z","iopub.execute_input":"2022-06-05T16:17:52.662007Z","iopub.status.idle":"2022-06-05T16:18:16.817059Z","shell.execute_reply.started":"2022-06-05T16:17:52.661964Z","shell.execute_reply":"2022-06-05T16:18:16.816151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:18:16.818716Z","iopub.execute_input":"2022-06-05T16:18:16.819762Z","iopub.status.idle":"2022-06-05T16:18:17.047564Z","shell.execute_reply.started":"2022-06-05T16:18:16.819719Z","shell.execute_reply":"2022-06-05T16:18:17.046568Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:18:17.049263Z","iopub.execute_input":"2022-06-05T16:18:17.049675Z","iopub.status.idle":"2022-06-05T16:18:17.239773Z","shell.execute_reply.started":"2022-06-05T16:18:17.049635Z","shell.execute_reply":"2022-06-05T16:18:17.238784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:18:17.2415Z","iopub.execute_input":"2022-06-05T16:18:17.241909Z","iopub.status.idle":"2022-06-05T16:18:17.249586Z","shell.execute_reply.started":"2022-06-05T16:18:17.241869Z","shell.execute_reply":"2022-06-05T16:18:17.248517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = add_datepart(train, 'S_2')","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:18:17.253475Z","iopub.execute_input":"2022-06-05T16:18:17.253972Z","iopub.status.idle":"2022-06-05T16:18:17.463157Z","shell.execute_reply.started":"2022-06-05T16:18:17.253927Z","shell.execute_reply":"2022-06-05T16:18:17.46176Z"},"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":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_columns = ['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-06-05T16:18:17.464124Z","iopub.status.idle":"2022-06-05T16:18:17.465001Z","shell.execute_reply.started":"2022-06-05T16:18:17.464736Z","shell.execute_reply":"2022-06-05T16:18:17.464761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns = train.columns.tolist()\ncont_columns = [column for column in columns if column not in cat_columns]\ncont_columns.remove('target')","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:18:17.466718Z","iopub.status.idle":"2022-06-05T16:18:17.467208Z","shell.execute_reply.started":"2022-06-05T16:18:17.466963Z","shell.execute_reply":"2022-06-05T16:18:17.466987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"procs = [Categorify, FillMissing]","metadata":{"execution":{"iopub.status.busy":"2022-06-05T16:18:17.468599Z","iopub.status.idle":"2022-06-05T16:18:17.469056Z","shell.execute_reply.started":"2022-06-05T16:18:17.468821Z","shell.execute_reply":"2022-06-05T16:18:17.468845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}