{"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\nimport matplotlib.pyplot as plt # visualize the data\nimport seaborn as sns # visualize the data\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.feature_selection import VarianceThreshold\nfrom sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier, AdaBoostClassifier\nfrom sklearn.metrics import roc_curve, roc_auc_score, accuracy_score, confusion_matrix\nfrom sklearn.preprocessing import StandardScaler, OrdinalEncoder, LabelEncoder, OneHotEncoder\nfrom sklearn.compose import ColumnTransformer\nimport pickle \nimport lightgbm as lgb\n\nimport warnings\n\nwarnings.simplefilter('ignore')\n\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\n%matplotlib inline","metadata":{"id":"e1decbe1","executionInfo":{"status":"ok","timestamp":1671735632411,"user_tz":-330,"elapsed":1819,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T12:06:11.385936Z","iopub.execute_input":"2022-12-24T12:06:11.386453Z","iopub.status.idle":"2022-12-24T12:06:14.321720Z","shell.execute_reply.started":"2022-12-24T12:06:11.386347Z","shell.execute_reply":"2022-12-24T12:06:14.321103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load data","metadata":{"id":"xctEUjdpeSiU"}},{"cell_type":"code","source":"df_train = pd.read_feather('/kaggle/input/amexfeather/train_data.ftr')\ndf_train.drop(['target'], axis = 1, inplace = True)\ndf_train","metadata":{"executionInfo":{"elapsed":22696,"status":"ok","timestamp":1671735655105,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"},"user_tz":-330},"id":"561882ce","outputId":"3a25630d-e60f-41e7-9cdd-7feefa255dd0","execution":{"iopub.status.busy":"2022-12-24T12:06:14.323091Z","iopub.execute_input":"2022-12-24T12:06:14.323526Z","iopub.status.idle":"2022-12-24T12:06:30.601271Z","shell.execute_reply.started":"2022-12-24T12:06:14.323493Z","shell.execute_reply":"2022-12-24T12:06:30.600472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_feather('/kaggle/input/amexfeather/test_data.ftr')\ndf_test","metadata":{"id":"LuFcRpm5Ll_W","executionInfo":{"status":"ok","timestamp":1671735655106,"user_tz":-330,"elapsed":5,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T12:06:30.602437Z","iopub.execute_input":"2022-12-24T12:06:30.602660Z","iopub.status.idle":"2022-12-24T12:06:58.662461Z","shell.execute_reply.started":"2022-12-24T12:06:30.602633Z","shell.execute_reply":"2022-12-24T12:06:58.661693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = pd.read_csv('/kaggle/input/amex-default-prediction/train_labels.csv')\ntarget","metadata":{"executionInfo":{"elapsed":454,"status":"ok","timestamp":1671735655556,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"},"user_tz":-330},"id":"8RK4uGUX1tYC","outputId":"66a4e070-6c74-476e-97af-774591558522","execution":{"iopub.status.busy":"2022-12-24T12:06:58.663609Z","iopub.execute_input":"2022-12-24T12:06:58.663816Z","iopub.status.idle":"2022-12-24T12:06:59.363728Z","shell.execute_reply.started":"2022-12-24T12:06:58.663790Z","shell.execute_reply":"2022-12-24T12:06:59.362963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{"id":"q9gpGEhd2Alp"}},{"cell_type":"code","source":"print(df_train.shape)\nprint(df_test.shape)\nprint(target.shape)","metadata":{"executionInfo":{"elapsed":6,"status":"ok","timestamp":1671735655557,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"},"user_tz":-330},"id":"WvgKZQ6WU25M","outputId":"bc562ff1-4cea-4390-b3cf-a52398f17069","execution":{"iopub.status.busy":"2022-12-24T12:06:59.365667Z","iopub.execute_input":"2022-12-24T12:06:59.365899Z","iopub.status.idle":"2022-12-24T12:06:59.371189Z","shell.execute_reply.started":"2022-12-24T12:06:59.365870Z","shell.execute_reply":"2022-12-24T12:06:59.370505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train","metadata":{"executionInfo":{"elapsed":971,"status":"ok","timestamp":1671735656524,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"},"user_tz":-330},"id":"F6qecMxoEKF3","outputId":"0ad68c84-b746-4a0e-e4ed-2ace6d62e540","execution":{"iopub.status.busy":"2022-12-24T12:06:59.372068Z","iopub.execute_input":"2022-12-24T12:06:59.372283Z","iopub.status.idle":"2022-12-24T12:07:00.338382Z","shell.execute_reply.started":"2022-12-24T12:06:59.372257Z","shell.execute_reply":"2022-12-24T12:07:00.337546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.info(verbose=True, null_counts=True)","metadata":{"id":"e5c8105d","execution":{"iopub.status.busy":"2022-12-24T12:07:00.339648Z","iopub.execute_input":"2022-12-24T12:07:00.339874Z","iopub.status.idle":"2022-12-24T12:07:04.377550Z","shell.execute_reply.started":"2022-12-24T12:07:00.339846Z","shell.execute_reply":"2022-12-24T12:07:04.376751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.select_dtypes(include = ['object', 'category']).columns","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:07:04.378765Z","iopub.execute_input":"2022-12-24T12:07:04.379016Z","iopub.status.idle":"2022-12-24T12:07:04.482141Z","shell.execute_reply.started":"2022-12-24T12:07:04.378984Z","shell.execute_reply":"2022-12-24T12:07:04.481384Z"},"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']\nnum_cols = []\nfor col in df_train.columns:\n    if col not in categorical_cols+['customer_ID','S_2']:\n        num_cols.append(col)\n\nnum_cols = np.array(num_cols)\nprint(\"categorical cols: \", categorical_cols)\nprint(\"numerical cols: \", num_cols)","metadata":{"executionInfo":{"elapsed":22,"status":"ok","timestamp":1671735659201,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"},"user_tz":-330},"id":"8ebb57d7","outputId":"cf1db901-ed5c-4ed2-f62e-60c933889319","execution":{"iopub.status.busy":"2022-12-24T12:07:04.483238Z","iopub.execute_input":"2022-12-24T12:07:04.483467Z","iopub.status.idle":"2022-12-24T12:07:04.491276Z","shell.execute_reply.started":"2022-12-24T12:07:04.483440Z","shell.execute_reply":"2022-12-24T12:07:04.490469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train[categorical_cols]","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:07:04.492234Z","iopub.execute_input":"2022-12-24T12:07:04.492432Z","iopub.status.idle":"2022-12-24T12:07:04.532106Z","shell.execute_reply.started":"2022-12-24T12:07:04.492394Z","shell.execute_reply":"2022-12-24T12:07:04.531472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def denoise(df):\n    df['D_63'] = df['D_63'].apply(lambda t: {'CR': 0, 'XZ': 1, 'XM': 2, 'CO': 3, 'CL': 4, 'XL': 5}[t]).astype(np.int8)\n    df['D_64'] = df['D_64'].apply(lambda t: {'O': 0, 'U': 3, 'R': 2, '': -1, '-1': 1}[t]).astype(np.int8)\n\n    return df\n\ndef variance(df):\n    df_temp = df.drop(['customer_ID','S_2'], axis=1)\n\n    var_thres = VarianceThreshold(threshold = 0)\n    var_thres.fit(df_temp)\n\n    constant_columns = [column for column in df_temp.columns if column not in df_temp.columns[var_thres.get_support()]]\n\n    df.drop(constant_columns, axis=1, inplace = True)\n    \n    return df\n\ndef null_details(threshold : np.int8 = 50, cols: np.ndarray = df_train.columns, df: pd.DataFrame = df_train) -> pd.DataFrame:\n    null_cols = df[cols].isnull().sum().sort_values()\n    df_null = pd.DataFrame(null_cols[null_cols > 0])\n    df_null[1] = df[cols].isnull().mean()*100\n\n    return df_null[df_null[1] > threshold]\n\ndef remove_cols(df):\n    return null_details(80, df.columns).index\n\ndef select_best_indeces(group: pd.DataFrame):\n    return group.isnull().sum(axis = 1).sort_values().head(1).index[0]\n\ndef select_rows(df_grouped):\n    return df_grouped.apply(select_best_indeces).values\n\ndef one_hot_encoding(df, cols, is_drop = True):\n    for col in cols:\n        print('one hot encoding:', col)\n        dummies = pd.get_dummies(pd.Series(df[col]), prefix =' oneHot_%s'%col, drop_first = True)\n        df = pd.concat([df, dummies], axis = 1)\n    if is_drop:\n        df.drop(cols, axis = 1, inplace = True)\n        \n    return df\n\ndef ordinal_encoding(df, cols):\n    enc = OrdinalEncoder()\n    df[cols] = enc.fit_transform(df[cols])\n    \n    return df","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:07:04.532989Z","iopub.execute_input":"2022-12-24T12:07:04.533180Z","iopub.status.idle":"2022-12-24T12:07:04.549548Z","shell.execute_reply.started":"2022-12-24T12:07:04.533157Z","shell.execute_reply":"2022-12-24T12:07:04.548773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_details(0, categorical_cols)","metadata":{"executionInfo":{"elapsed":15,"status":"ok","timestamp":1671735659202,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"},"user_tz":-330},"id":"I49QcffdSk_T","outputId":"0a3759f5-85e9-47a4-abea-f5b55d5dbe40","execution":{"iopub.status.busy":"2022-12-24T12:07:04.550575Z","iopub.execute_input":"2022-12-24T12:07:04.550817Z","iopub.status.idle":"2022-12-24T12:07:04.707005Z","shell.execute_reply.started":"2022-12-24T12:07:04.550791Z","shell.execute_reply":"2022-12-24T12:07:04.706250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pd.set_option('display.max_rows', None)\nnull_details(0, num_cols)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:07:04.708272Z","iopub.execute_input":"2022-12-24T12:07:04.708985Z","iopub.status.idle":"2022-12-24T12:07:13.892331Z","shell.execute_reply.started":"2022-12-24T12:07:04.708941Z","shell.execute_reply":"2022-12-24T12:07:13.891594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D_cols = df_train.columns[pd.Series(df_train.columns).str.startswith('D_')]\nB_cols = df_train.columns[pd.Series(df_train.columns).str.startswith('B_')]\nS_cols = df_train.columns[pd.Series(df_train.columns).str.startswith('S_')]\nR_cols = df_train.columns[pd.Series(df_train.columns).str.startswith('R_')]\nP_cols = df_train.columns[pd.Series(df_train.columns).str.startswith('P_')]\n\nDict = {'Delinquency': len(D_cols), 'Spend': len(S_cols), 'Payment': len(P_cols), 'Balance': len(B_cols), 'Risk': len(R_cols),}\n\nplt.figure(figsize=(10,5))\nsns.barplot(x=list(Dict.keys()), y=list(Dict.values()));\nplt.legend()","metadata":{"id":"nZ4gyuGK6SNF","executionInfo":{"status":"ok","timestamp":1671735675284,"user_tz":-330,"elapsed":427,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T12:07:13.895590Z","iopub.execute_input":"2022-12-24T12:07:13.895816Z","iopub.status.idle":"2022-12-24T12:07:14.255930Z","shell.execute_reply.started":"2022-12-24T12:07:13.895788Z","shell.execute_reply":"2022-12-24T12:07:14.255183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grouped_df = df_train.dropna(how='all').groupby(\"customer_ID\")","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:07:14.256927Z","iopub.execute_input":"2022-12-24T12:07:14.257149Z","iopub.status.idle":"2022-12-24T12:07:22.045733Z","shell.execute_reply.started":"2022-12-24T12:07:14.257121Z","shell.execute_reply":"2022-12-24T12:07:22.044997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"selected_indices = select_rows(grouped_df)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:07:22.046794Z","iopub.execute_input":"2022-12-24T12:07:22.047183Z","iopub.status.idle":"2022-12-24T12:23:12.022490Z","shell.execute_reply.started":"2022-12-24T12:07:22.047153Z","shell.execute_reply":"2022-12-24T12:23:12.021350Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = df_train.loc[selected_indices, :]\ndf_train","metadata":{"id":"XZxMeH7a5T9r","executionInfo":{"status":"ok","timestamp":1671736184108,"user_tz":-330,"elapsed":9,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"978fce42-ec0f-4b65-afc6-0a7d8bb67b3a","execution":{"iopub.status.busy":"2022-12-24T12:23:12.023813Z","iopub.execute_input":"2022-12-24T12:23:12.024061Z","iopub.status.idle":"2022-12-24T12:23:12.558464Z","shell.execute_reply.started":"2022-12-24T12:23:12.024032Z","shell.execute_reply":"2022-12-24T12:23:12.557700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe()","metadata":{"id":"25e6VELnTxIM","executionInfo":{"status":"ok","timestamp":1671736189525,"user_tz":-330,"elapsed":3382,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"8fef4b4c-42f3-4702-e114-83bf5aff44a9","execution":{"iopub.status.busy":"2022-12-24T12:23:12.559638Z","iopub.execute_input":"2022-12-24T12:23:12.559880Z","iopub.status.idle":"2022-12-24T12:23:24.169041Z","shell.execute_reply.started":"2022-12-24T12:23:12.559849Z","shell.execute_reply":"2022-12-24T12:23:24.168267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_details(0, df_train.columns, df_train)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:23:24.170232Z","iopub.execute_input":"2022-12-24T12:23:24.170497Z","iopub.status.idle":"2022-12-24T12:23:25.126439Z","shell.execute_reply.started":"2022-12-24T12:23:24.170463Z","shell.execute_reply":"2022-12-24T12:23:25.125677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = denoise(df_train)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:23:25.127497Z","iopub.execute_input":"2022-12-24T12:23:25.127703Z","iopub.status.idle":"2022-12-24T12:23:25.138835Z","shell.execute_reply.started":"2022-12-24T12:23:25.127676Z","shell.execute_reply":"2022-12-24T12:23:25.138094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"removeble_cols = list(remove_cols(df_train))\nremoveble_cols.append('S_2')","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:23:25.139868Z","iopub.execute_input":"2022-12-24T12:23:25.140123Z","iopub.status.idle":"2022-12-24T12:23:36.111539Z","shell.execute_reply.started":"2022-12-24T12:23:25.140094Z","shell.execute_reply":"2022-12-24T12:23:36.110514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"removeble_cols","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:23:36.112905Z","iopub.execute_input":"2022-12-24T12:23:36.113176Z","iopub.status.idle":"2022-12-24T12:23:36.118771Z","shell.execute_reply.started":"2022-12-24T12:23:36.113129Z","shell.execute_reply":"2022-12-24T12:23:36.118001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in df_train.iloc[:, 2:].columns:\n    if col not in removeble_cols:\n        if col in categorical_cols:\n            df_train[col] = df_train[col].fillna(df_train[col].mode()[0])\n        else:\n            df_train[col] = df_train[col].fillna(df_train[col].median())\n\nnull_details(0, df_train.columns, df_train)","metadata":{"id":"uRVkVz7TDAD6","executionInfo":{"status":"ok","timestamp":1671737128763,"user_tz":-330,"elapsed":1409,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"9ecd0d91-46c7-4c58-d8b3-0240954d7f3b","execution":{"iopub.status.busy":"2022-12-24T12:23:36.119673Z","iopub.execute_input":"2022-12-24T12:23:36.119853Z","iopub.status.idle":"2022-12-24T12:23:39.249466Z","shell.execute_reply.started":"2022-12-24T12:23:36.119830Z","shell.execute_reply":"2022-12-24T12:23:39.248740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:23:39.250514Z","iopub.execute_input":"2022-12-24T12:23:39.250723Z","iopub.status.idle":"2022-12-24T12:23:39.355388Z","shell.execute_reply.started":"2022-12-24T12:23:39.250696Z","shell.execute_reply":"2022-12-24T12:23:39.354633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA on Test Data","metadata":{}},{"cell_type":"code","source":"nans = null_details(0, df_test.columns, df_test)\nprint(nans)\nprint(nans.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:23:39.356458Z","iopub.execute_input":"2022-12-24T12:23:39.356664Z","iopub.status.idle":"2022-12-24T12:24:01.792752Z","shell.execute_reply.started":"2022-12-24T12:23:39.356638Z","shell.execute_reply":"2022-12-24T12:24:01.791830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"grouped_df_test = df_test.dropna(how='all').groupby(\"customer_ID\")","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:24:01.794081Z","iopub.execute_input":"2022-12-24T12:24:01.794347Z","iopub.status.idle":"2022-12-24T12:24:18.221109Z","shell.execute_reply.started":"2022-12-24T12:24:01.794312Z","shell.execute_reply":"2022-12-24T12:24:18.220234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rows_indices = select_rows(grouped_df_test)\nrows_indices","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:24:18.222292Z","iopub.execute_input":"2022-12-24T12:24:18.222537Z","iopub.status.idle":"2022-12-24T12:55:58.748815Z","shell.execute_reply.started":"2022-12-24T12:24:18.222507Z","shell.execute_reply":"2022-12-24T12:55:58.748113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = df_test.loc[rows_indices, :]\ndf_test","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:55:58.749966Z","iopub.execute_input":"2022-12-24T12:55:58.750188Z","iopub.status.idle":"2022-12-24T12:55:59.957027Z","shell.execute_reply.started":"2022-12-24T12:55:58.750151Z","shell.execute_reply":"2022-12-24T12:55:59.956455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_details(0, df_test.columns, df_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:55:59.957976Z","iopub.execute_input":"2022-12-24T12:55:59.958211Z","iopub.status.idle":"2022-12-24T12:56:01.866137Z","shell.execute_reply.started":"2022-12-24T12:55:59.958183Z","shell.execute_reply":"2022-12-24T12:56:01.865442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = denoise(df_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:01.867160Z","iopub.execute_input":"2022-12-24T12:56:01.867694Z","iopub.status.idle":"2022-12-24T12:56:01.883452Z","shell.execute_reply.started":"2022-12-24T12:56:01.867665Z","shell.execute_reply":"2022-12-24T12:56:01.882795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in df_test.iloc[:, 2:].columns:\n    if col not in removeble_cols:\n        if col in categorical_cols:\n            df_test[col] = df_test[col].fillna(df_test[col].mode()[0])\n        else:\n            df_test[col] = df_test[col].fillna(df_test[col].median())\n\nnull_details(0, df_test.columns, df_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:01.884346Z","iopub.execute_input":"2022-12-24T12:56:01.884587Z","iopub.status.idle":"2022-12-24T12:56:08.259070Z","shell.execute_reply.started":"2022-12-24T12:56:01.884559Z","shell.execute_reply":"2022-12-24T12:56:08.258339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test['D_68'] = pd.Categorical(df_test['D_68'], categories=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], ordered=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:08.259963Z","iopub.execute_input":"2022-12-24T12:56:08.260319Z","iopub.status.idle":"2022-12-24T12:56:08.268401Z","shell.execute_reply.started":"2022-12-24T12:56:08.260292Z","shell.execute_reply":"2022-12-24T12:56:08.267851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:08.269233Z","iopub.execute_input":"2022-12-24T12:56:08.269409Z","iopub.status.idle":"2022-12-24T12:56:08.495445Z","shell.execute_reply.started":"2022-12-24T12:56:08.269386Z","shell.execute_reply":"2022-12-24T12:56:08.494656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Handle Categorical Data","metadata":{}},{"cell_type":"code","source":"for col in ['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_68']:\n    le = LabelEncoder()\n    le.fit(df_train[col])\n    print('*****')\n    print(col)\n    print(le.classes_)\n    print(df_test[col].unique())\n    print(df_train[col].unique())\n    print('*****')\n    df_train[col] = le.transform(df_train[col])\n    df_test[col] = le.transform(df_test[col])\ndf_train[['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_68']]","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:08.496572Z","iopub.execute_input":"2022-12-24T12:56:08.496817Z","iopub.status.idle":"2022-12-24T12:56:09.274506Z","shell.execute_reply.started":"2022-12-24T12:56:08.496786Z","shell.execute_reply":"2022-12-24T12:56:09.273880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ct = ColumnTransformer([('oneHot', OneHotEncoder(drop='first'), ['B_30', 'B_38', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126', 'D_68'])], remainder = 'passthrough')","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:09.275509Z","iopub.execute_input":"2022-12-24T12:56:09.275736Z","iopub.status.idle":"2022-12-24T12:56:09.280144Z","shell.execute_reply.started":"2022-12-24T12:56:09.275707Z","shell.execute_reply":"2022-12-24T12:56:09.279592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_matrix = ct.fit_transform(df_train)\ntest_matrix = ct.transform(df_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:09.281053Z","iopub.execute_input":"2022-12-24T12:56:09.281249Z","iopub.status.idle":"2022-12-24T12:56:44.921872Z","shell.execute_reply.started":"2022-12-24T12:56:09.281226Z","shell.execute_reply":"2022-12-24T12:56:44.920728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_features = ct.get_feature_names()","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:44.923209Z","iopub.execute_input":"2022-12-24T12:56:44.923486Z","iopub.status.idle":"2022-12-24T12:56:44.928128Z","shell.execute_reply.started":"2022-12-24T12:56:44.923453Z","shell.execute_reply":"2022-12-24T12:56:44.927293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_matrix.dtype","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:44.929202Z","iopub.execute_input":"2022-12-24T12:56:44.929447Z","iopub.status.idle":"2022-12-24T12:56:44.945545Z","shell.execute_reply.started":"2022-12-24T12:56:44.929403Z","shell.execute_reply":"2022-12-24T12:56:44.944741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.DataFrame(train_matrix, columns = new_features)\ndf_train.set_index('customer_ID', drop = True, inplace = True)\ndf_train","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:44.946497Z","iopub.execute_input":"2022-12-24T12:56:44.946725Z","iopub.status.idle":"2022-12-24T12:56:56.862499Z","shell.execute_reply.started":"2022-12-24T12:56:44.946699Z","shell.execute_reply":"2022-12-24T12:56:56.861716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.DataFrame(test_matrix, columns = new_features)\ndf_test.set_index('customer_ID', drop = True, inplace = True)\ndf_test","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:56:56.863705Z","iopub.execute_input":"2022-12-24T12:56:56.863951Z","iopub.status.idle":"2022-12-24T12:57:14.775329Z","shell.execute_reply.started":"2022-12-24T12:56:56.863921Z","shell.execute_reply":"2022-12-24T12:57:14.774596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Featuture Selection","metadata":{}},{"cell_type":"code","source":"df_train.loc[:, pd.Series(df_train.columns).str.startswith('oneHot').values] = df_train.loc[:, pd.Series(df_train.columns).str.startswith('oneHot').values].astype('int8')","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:57:14.779829Z","iopub.execute_input":"2022-12-24T12:57:14.780061Z","iopub.status.idle":"2022-12-24T12:58:09.173431Z","shell.execute_reply.started":"2022-12-24T12:57:14.780033Z","shell.execute_reply":"2022-12-24T12:58:09.172478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.loc[:, list(df_train.select_dtypes(include=['object']).columns)] = df_train.loc[:, list(df_train.select_dtypes(include=['object']).columns)].astype('float64')","metadata":{"execution":{"iopub.status.busy":"2022-12-24T12:58:09.174632Z","iopub.execute_input":"2022-12-24T12:58:09.174870Z","iopub.status.idle":"2022-12-24T13:00:50.427478Z","shell.execute_reply.started":"2022-12-24T12:58:09.174840Z","shell.execute_reply":"2022-12-24T13:00:50.426414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.dtypes.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:00:50.428740Z","iopub.execute_input":"2022-12-24T13:00:50.428978Z","iopub.status.idle":"2022-12-24T13:00:50.437264Z","shell.execute_reply.started":"2022-12-24T13:00:50.428950Z","shell.execute_reply":"2022-12-24T13:00:50.436516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cor_matrix = df_train.corr()\ncol_core = set()\n\nfor i in range(len(cor_matrix.columns)):\n    for j in range(i):\n        if(cor_matrix.iloc[i, j] > 0.9):\n            col_name = cor_matrix.columns[i]\n            col_core.add(col_name)\n            \ncol_core","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:00:50.438246Z","iopub.execute_input":"2022-12-24T13:00:50.438457Z","iopub.status.idle":"2022-12-24T13:01:32.245784Z","shell.execute_reply.started":"2022-12-24T13:00:50.438413Z","shell.execute_reply":"2022-12-24T13:01:32.244894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,5))\nsns.heatmap(cor_matrix, cmap = plt.cm.Accent_r, annot = True)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:01:32.247041Z","iopub.execute_input":"2022-12-24T13:01:32.247297Z","iopub.status.idle":"2022-12-24T13:04:40.309106Z","shell.execute_reply.started":"2022-12-24T13:01:32.247264Z","shell.execute_reply":"2022-12-24T13:04:40.308444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dropable_cols = np.concatenate((removeble_cols, list(col_core)))\ndropable_cols","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:04:40.310195Z","iopub.execute_input":"2022-12-24T13:04:40.310405Z","iopub.status.idle":"2022-12-24T13:04:40.316098Z","shell.execute_reply.started":"2022-12-24T13:04:40.310377Z","shell.execute_reply":"2022-12-24T13:04:40.315563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(dropable_cols, axis = 1, inplace = True)\ndf_train","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:04:40.316916Z","iopub.execute_input":"2022-12-24T13:04:40.317115Z","iopub.status.idle":"2022-12-24T13:04:41.201130Z","shell.execute_reply.started":"2022-12-24T13:04:40.317083Z","shell.execute_reply":"2022-12-24T13:04:41.200592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.drop(dropable_cols, axis = 1, inplace = True)\ndf_test","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:04:41.202112Z","iopub.execute_input":"2022-12-24T13:04:41.202316Z","iopub.status.idle":"2022-12-24T13:04:54.163076Z","shell.execute_reply.started":"2022-12-24T13:04:41.202291Z","shell.execute_reply":"2022-12-24T13:04:54.162468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train Model","metadata":{"id":"zDZ2aqiuk7Jd"}},{"cell_type":"code","source":"target.set_index('customer_ID', drop = True, inplace = True)\nmerged_df = pd.concat([df_train, target], axis = 1)\nmerged_df","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:04:54.164146Z","iopub.execute_input":"2022-12-24T13:04:54.164362Z","iopub.status.idle":"2022-12-24T13:04:54.873155Z","shell.execute_reply.started":"2022-12-24T13:04:54.164336Z","shell.execute_reply":"2022-12-24T13:04:54.872406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nX = merged_df.drop('target', axis = 1)\ny = merged_df['target']\nX","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:04:54.874230Z","iopub.execute_input":"2022-12-24T13:04:54.874487Z","iopub.status.idle":"2022-12-24T13:04:55.335937Z","shell.execute_reply.started":"2022-12-24T13:04:54.874455Z","shell.execute_reply":"2022-12-24T13:04:55.335192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)","metadata":{"id":"c62fbef0","executionInfo":{"status":"ok","timestamp":1671737829484,"user_tz":-330,"elapsed":851,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T13:04:55.337016Z","iopub.execute_input":"2022-12-24T13:04:55.337237Z","iopub.status.idle":"2022-12-24T13:04:56.424851Z","shell.execute_reply.started":"2022-12-24T13:04:55.337209Z","shell.execute_reply":"2022-12-24T13:04:56.424030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = StandardScaler()\nX_train_scaled = scaler.fit_transform(X_train)\nX_test_scaled = scaler.transform(X_test)\ndf_test_scaled = scaler.transform(df_test)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:04:56.425983Z","iopub.execute_input":"2022-12-24T13:04:56.426407Z","iopub.status.idle":"2022-12-24T13:05:08.288010Z","shell.execute_reply.started":"2022-12-24T13:04:56.426373Z","shell.execute_reply":"2022-12-24T13:05:08.287193Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_scaled","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:05:08.289056Z","iopub.execute_input":"2022-12-24T13:05:08.289282Z","iopub.status.idle":"2022-12-24T13:05:08.294772Z","shell.execute_reply.started":"2022-12-24T13:05:08.289255Z","shell.execute_reply":"2022-12-24T13:05:08.294130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ran_clf = RandomForestClassifier(n_estimators = 10, max_depth = 2, random_state=0)\nada_clf = AdaBoostClassifier()\ngbm_clf = GradientBoostingClassifier()","metadata":{"id":"b495f6a8","executionInfo":{"status":"ok","timestamp":1671737829485,"user_tz":-330,"elapsed":3,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T13:05:08.295661Z","iopub.execute_input":"2022-12-24T13:05:08.295875Z","iopub.status.idle":"2022-12-24T13:05:08.305462Z","shell.execute_reply.started":"2022-12-24T13:05:08.295830Z","shell.execute_reply":"2022-12-24T13:05:08.304872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_train = lgb.Dataset(data = X_train_scaled, label = y_train)\n\nparams = {'objective': 'binary','n_estimators': 1200,'metric': 'binary_logloss','boosting': 'gbdt','num_leaves': 90,'reg_lambda' : 50,'colsample_bytree': 0.19,'learning_rate': 0.03,'min_child_samples': 2400,'max_bins': 511,'seed': 42,'verbose': -1}\n\nlgb_clf = lgb.train(params, d_train, 100)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:51:49.638300Z","iopub.execute_input":"2022-12-24T13:51:49.638877Z","iopub.status.idle":"2022-12-24T13:53:30.531602Z","shell.execute_reply.started":"2022-12-24T13:51:49.638844Z","shell.execute_reply":"2022-12-24T13:53:30.530588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=[]\npred_prob = []\n\nfor model in [ran_clf,ada_clf,gbm_clf]:\n    model.fit(X_train_scaled, y_train)\n    pred.append(model.predict(X_test_scaled))\n    pred_prob.append(model.predict_proba(X_test_scaled))","metadata":{"id":"6ri0hNv3zQSH","executionInfo":{"status":"ok","timestamp":1671737917632,"user_tz":-330,"elapsed":5956,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"2bfa8a03-6406-4e7f-e4fe-b5b49b0f705b","execution":{"iopub.status.busy":"2022-12-24T13:06:30.500921Z","iopub.execute_input":"2022-12-24T13:06:30.501155Z","iopub.status.idle":"2022-12-24T13:32:52.875286Z","shell.execute_reply.started":"2022-12-24T13:06:30.501128Z","shell.execute_reply":"2022-12-24T13:32:52.874229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicts = [pd.Series(x) for x in pred]\nprobabilities = [pd.DataFrame(x, columns = [0, 1]) for x in pred_prob]","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:58:15.089519Z","iopub.execute_input":"2022-12-24T13:58:15.090341Z","iopub.status.idle":"2022-12-24T13:58:15.095508Z","shell.execute_reply.started":"2022-12-24T13:58:15.090305Z","shell.execute_reply":"2022-12-24T13:58:15.094854Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgb_pred = lgb_clf.predict(X_test_scaled)\nlgb_pred","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:58:17.445797Z","iopub.execute_input":"2022-12-24T13:58:17.446451Z","iopub.status.idle":"2022-12-24T13:58:17.903904Z","shell.execute_reply.started":"2022-12-24T13:58:17.446404Z","shell.execute_reply":"2022-12-24T13:58:17.902919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicts.append(pd.Series(lgb_pred))\n# probabilities.append(pd.DataFrame(lgb_prob, columns = [0, 1]))","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:58:22.485997Z","iopub.execute_input":"2022-12-24T13:58:22.487041Z","iopub.status.idle":"2022-12-24T13:58:22.491135Z","shell.execute_reply.started":"2022-12-24T13:58:22.486996Z","shell.execute_reply":"2022-12-24T13:58:22.490386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = pd.concat(predicts, axis = 1)\ny_pred","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:58:24.894710Z","iopub.execute_input":"2022-12-24T13:58:24.895024Z","iopub.status.idle":"2022-12-24T13:58:24.909553Z","shell.execute_reply.started":"2022-12-24T13:58:24.894989Z","shell.execute_reply":"2022-12-24T13:58:24.908687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_prob = pd.concat(probabilities, axis = 1)\ny_prob","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:58:28.748013Z","iopub.execute_input":"2022-12-24T13:58:28.748342Z","iopub.status.idle":"2022-12-24T13:58:28.768242Z","shell.execute_reply.started":"2022-12-24T13:58:28.748304Z","shell.execute_reply":"2022-12-24T13:58:28.767364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lgb_clf.predict(X_test_scaled)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:59:13.297161Z","iopub.execute_input":"2022-12-24T13:59:13.297494Z","iopub.status.idle":"2022-12-24T13:59:13.766288Z","shell.execute_reply.started":"2022-12-24T13:59:13.297456Z","shell.execute_reply":"2022-12-24T13:59:13.765320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# AMEX Metric","metadata":{"id":"FA7Hl7xrl9Dn"}},{"cell_type":"code","source":"def amex_metric(y_true: pd.DataFrame, y_pred: pd.DataFrame) -> float:\n\n    def top_four_percent_captured(y_true: pd.DataFrame, y_pred: pd.DataFrame) -> float:\n        df = (pd.concat([y_true, y_pred], axis='columns')\n              .sort_values('prediction', ascending=False))\n        df['weight'] = df['target'].apply(lambda x: 20 if x==0 else 1)\n        four_pct_cutoff = int(0.04 * df['weight'].sum())\n        df['weight_cumsum'] = df['weight'].cumsum()\n        df_cutoff = df.loc[df['weight_cumsum'] <= four_pct_cutoff]\n        return (df_cutoff['target'] == 1).sum() / (df['target'] == 1).sum()\n\n    def weighted_gini(y_true: pd.DataFrame, y_pred: pd.DataFrame) -> float:\n        df = (pd.concat([y_true, y_pred], axis='columns')\n              .sort_values('prediction', ascending=False))\n        df['weight'] = df['target'].apply(lambda x: 20 if x==0 else 1)\n        df['random'] = (df['weight'] / df['weight'].sum()).cumsum()\n        total_pos = (df['target'] * df['weight']).sum()\n        df['cum_pos_found'] = (df['target'] * df['weight']).cumsum()\n        df['lorentz'] = df['cum_pos_found'] / total_pos\n        df['gini'] = (df['lorentz'] - df['random']) * df['weight']\n        return df['gini'].sum()\n\n    def normalized_weighted_gini(y_true: pd.DataFrame, y_pred: pd.DataFrame) -> float:\n        y_true_pred = y_true.rename(columns={'target': 'prediction'})\n        return weighted_gini(y_true, y_pred) / weighted_gini(y_true, y_true_pred)\n\n    g = normalized_weighted_gini(y_true, y_pred)\n    d = top_four_percent_captured(y_true, y_pred)\n\n    return 0.5 * (g + d)\n\ndef amex_metric_mod(y_true, y_pred):\n\n    labels     = np.transpose(np.array([y_true, y_pred]))\n    labels     = labels[labels[:, 1].argsort()[::-1]]\n    weights    = np.where(labels[:,0]==0, 20, 1)\n    cut_vals   = labels[np.cumsum(weights) <= int(0.04 * np.sum(weights))]\n    top_four   = np.sum(cut_vals[:,0]) / np.sum(labels[:,0])\n\n    gini = [0,0]\n    for i in [1,0]:\n        labels         = np.transpose(np.array([y_true, y_pred]))\n        labels         = labels[labels[:, i].argsort()[::-1]]\n        weight         = np.where(labels[:,0]==0, 20, 1)\n        weight_random  = np.cumsum(weight / np.sum(weight))\n        total_pos      = np.sum(labels[:, 0] *  weight)\n        cum_pos_found  = np.cumsum(labels[:, 0] * weight)\n        lorentz        = cum_pos_found / total_pos\n        gini[i]        = np.sum((lorentz - weight_random) * weight)\n\n    return 0.5 * (gini[1]/gini[0] + top_four)","metadata":{"id":"g5rVSoLvmASu","executionInfo":{"status":"ok","timestamp":1671737948109,"user_tz":-330,"elapsed":461,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T13:36:06.864658Z","iopub.execute_input":"2022-12-24T13:36:06.865223Z","iopub.status.idle":"2022-12-24T13:36:06.884997Z","shell.execute_reply.started":"2022-12-24T13:36:06.865189Z","shell.execute_reply":"2022-12-24T13:36:06.884342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Perfomance Matices","metadata":{"id":"8iAFWY3FnNZX"}},{"cell_type":"code","source":"def plot_roc_curve(fpr, tpr):\n    plt.plot(fpr, tpr, color='orange', label='ROC')\n    plt.plot([0, 1], [0, 1], color='darkblue', linestyle='--', label='Default')\n    plt.xlabel('False Positive Rate')\n    plt.ylabel('True Positive Rate')\n    plt.title('Receiver Operating Characteristic (ROC) Curve')\n    plt.legend()\n    plt.show()","metadata":{"id":"pAsvoXRQnSwn","executionInfo":{"status":"ok","timestamp":1671737951195,"user_tz":-330,"elapsed":523,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T13:36:12.343572Z","iopub.execute_input":"2022-12-24T13:36:12.344299Z","iopub.status.idle":"2022-12-24T13:36:12.349545Z","shell.execute_reply.started":"2022-12-24T13:36:12.344254Z","shell.execute_reply":"2022-12-24T13:36:12.348869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test, y_pred.loc[:, [3]])","metadata":{"id":"SyG-gTXGmo1f","executionInfo":{"status":"ok","timestamp":1671737951649,"user_tz":-330,"elapsed":9,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"21cfabae-5b4f-4855-ff1d-c7316a6b13a6","execution":{"iopub.status.busy":"2022-12-24T13:49:16.499812Z","iopub.execute_input":"2022-12-24T13:49:16.500301Z","iopub.status.idle":"2022-12-24T13:49:16.513736Z","shell.execute_reply.started":"2022-12-24T13:49:16.500266Z","shell.execute_reply":"2022-12-24T13:49:16.513059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"amex_metric_mod(y_test.values, y_prob.iloc[:, [7]].values.flatten())","metadata":{"id":"2dknOw36n-8w","executionInfo":{"status":"ok","timestamp":1671737952561,"user_tz":-330,"elapsed":918,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"48f0890e-72fc-4367-819a-701737c6d0bf","execution":{"iopub.status.busy":"2022-12-24T13:42:48.092662Z","iopub.execute_input":"2022-12-24T13:42:48.093353Z","iopub.status.idle":"2022-12-24T13:42:48.130973Z","shell.execute_reply.started":"2022-12-24T13:42:48.093318Z","shell.execute_reply":"2022-12-24T13:42:48.130276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"amex_metric_mod(y_test.values, lgb_pred)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:55:21.641052Z","iopub.execute_input":"2022-12-24T13:55:21.641611Z","iopub.status.idle":"2022-12-24T13:55:21.679896Z","shell.execute_reply.started":"2022-12-24T13:55:21.641570Z","shell.execute_reply":"2022-12-24T13:55:21.679145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"roc_auc_score(y_test, y_prob.iloc[:, [5]].values.flatten())","metadata":{"id":"7WEXqzMLqWvd","executionInfo":{"status":"ok","timestamp":1671737952562,"user_tz":-330,"elapsed":8,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"eb36a7fc-46bb-4d87-d6c6-e0e2701197f9","execution":{"iopub.status.busy":"2022-12-24T13:51:09.204748Z","iopub.execute_input":"2022-12-24T13:51:09.205443Z","iopub.status.idle":"2022-12-24T13:51:09.237804Z","shell.execute_reply.started":"2022-12-24T13:51:09.205396Z","shell.execute_reply":"2022-12-24T13:51:09.237101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fpr, tpr, thresholds = roc_curve(y_test, y_prob.iloc[:, [7]].values.flatten())\nplt.figure(figsize=(16, 9))\nplot_roc_curve(fpr, tpr)","metadata":{"id":"jWe2WOXpm1jn","executionInfo":{"status":"ok","timestamp":1671737952562,"user_tz":-330,"elapsed":5,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"outputId":"30ef9e0b-5292-4856-fd60-2c1c520c0319","execution":{"iopub.status.busy":"2022-12-24T13:44:49.476252Z","iopub.execute_input":"2022-12-24T13:44:49.476982Z","iopub.status.idle":"2022-12-24T13:44:49.708850Z","shell.execute_reply.started":"2022-12-24T13:44:49.476947Z","shell.execute_reply":"2022-12-24T13:44:49.708198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{"id":"5TGhjiRqKMWU"}},{"cell_type":"code","source":"predict_prob = lgb_clf.predict(df_test_scaled)#[:, 1].reshape(-1,1).flatten()\npredict_prob","metadata":{"id":"HzsfIGZUKz29","executionInfo":{"status":"aborted","timestamp":1671736191177,"user_tz":-330,"elapsed":16,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T13:56:42.473669Z","iopub.execute_input":"2022-12-24T13:56:42.474484Z","iopub.status.idle":"2022-12-24T13:56:46.906414Z","shell.execute_reply.started":"2022-12-24T13:56:42.474439Z","shell.execute_reply":"2022-12-24T13:56:46.905638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(predict_prob)","metadata":{"execution":{"iopub.status.busy":"2022-12-24T13:56:51.622527Z","iopub.execute_input":"2022-12-24T13:56:51.623050Z","iopub.status.idle":"2022-12-24T13:56:51.627618Z","shell.execute_reply.started":"2022-12-24T13:56:51.623018Z","shell.execute_reply":"2022-12-24T13:56:51.627004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_dataset = pd.read_csv('/kaggle/input/amex-default-prediction/sample_submission.csv')\noutput = pd.DataFrame({'customer_ID': df_test.index, 'prediction': predict_prob})\noutput.to_csv('/kaggle/working/my_submission_7.zip', index = False, compression = 'zip')","metadata":{"id":"AvTXhnebLQ4d","executionInfo":{"status":"aborted","timestamp":1671736191178,"user_tz":-330,"elapsed":16,"user":{"displayName":"Sathulakjan Thayaparan","userId":"05850266884036254021"}},"execution":{"iopub.status.busy":"2022-12-24T13:56:53.963690Z","iopub.execute_input":"2022-12-24T13:56:53.964367Z","iopub.status.idle":"2022-12-24T13:57:05.830792Z","shell.execute_reply.started":"2022-12-24T13:56:53.964333Z","shell.execute_reply":"2022-12-24T13:57:05.829979Z"},"trusted":true},"execution_count":null,"outputs":[]}]}