{"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":"import numpy as np \nimport pandas as pd \nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.utils import resample\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier\nfrom xgboost import XGBClassifier\nfrom sklearn.model_selection import cross_validate, cross_val_score\nfrom sklearn.metrics import confusion_matrix, classification_report, accuracy_score\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-09-30T08:29:01.675186Z","iopub.execute_input":"2023-09-30T08:29:01.675822Z","iopub.status.idle":"2023-09-30T08:29:02.722791Z","shell.execute_reply.started":"2023-09-30T08:29:01.675699Z","shell.execute_reply":"2023-09-30T08:29:02.721542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data preprocessing","metadata":{}},{"cell_type":"code","source":"df_train = pd.read_parquet('/kaggle/input/amex-parquet/train_data.parquet')\ndf_test = pd.read_parquet('/kaggle/input/amex-parquet/test_data.parquet')","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:29:04.176384Z","iopub.execute_input":"2023-09-30T08:29:04.176905Z","iopub.status.idle":"2023-09-30T08:31:02.917505Z","shell.execute_reply.started":"2023-09-30T08:29:04.176866Z","shell.execute_reply":"2023-09-30T08:31:02.915163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.shape, df_test.shape","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:36:14.455007Z","iopub.execute_input":"2023-09-30T08:36:14.455590Z","iopub.status.idle":"2023-09-30T08:36:14.467641Z","shell.execute_reply.started":"2023-09-30T08:36:14.455527Z","shell.execute_reply":"2023-09-30T08:36:14.466770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.describe().T","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:36:18.153717Z","iopub.execute_input":"2023-09-30T08:36:18.154104Z","iopub.status.idle":"2023-09-30T08:37:19.980487Z","shell.execute_reply.started":"2023-09-30T08:36:18.154074Z","shell.execute_reply":"2023-09-30T08:37:19.979405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Knowing null values and drop it**","metadata":{}},{"cell_type":"code","source":"total = df_train.isnull().sum().sort_values(ascending=False)\npercent = (df_train.isnull().sum()/df_train.isnull().count()).sort_values(ascending=False)\nmissing_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])\nmissing_data.head(60)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:37:53.612863Z","iopub.execute_input":"2023-09-30T08:37:53.613299Z","iopub.status.idle":"2023-09-30T08:38:05.042460Z","shell.execute_reply.started":"2023-09-30T08:37:53.613253Z","shell.execute_reply":"2023-09-30T08:38:05.041643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null_columns = df_train.columns[df_train.isnull().any()]","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:57:57.087400Z","iopub.execute_input":"2023-09-30T08:57:57.088176Z","iopub.status.idle":"2023-09-30T08:57:59.297143Z","shell.execute_reply.started":"2023-09-30T08:57:57.088121Z","shell.execute_reply":"2023-09-30T08:57:59.295768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(columns=null_columns, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:17.467269Z","iopub.execute_input":"2023-09-30T08:58:17.467753Z","iopub.status.idle":"2023-09-30T08:58:19.286311Z","shell.execute_reply.started":"2023-09-30T08:58:17.467717Z","shell.execute_reply":"2023-09-30T08:58:19.284739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.drop(columns=null_columns, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:22.191132Z","iopub.execute_input":"2023-09-30T08:58:22.191650Z","iopub.status.idle":"2023-09-30T08:58:25.998162Z","shell.execute_reply.started":"2023-09-30T08:58:22.191612Z","shell.execute_reply":"2023-09-30T08:58:25.996000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:27.605725Z","iopub.execute_input":"2023-09-30T08:58:27.606179Z","iopub.status.idle":"2023-09-30T08:58:30.187268Z","shell.execute_reply.started":"2023-09-30T08:58:27.606146Z","shell.execute_reply":"2023-09-30T08:58:30.186290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(columns=['customer_ID'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:33.825138Z","iopub.execute_input":"2023-09-30T08:58:33.826181Z","iopub.status.idle":"2023-09-30T08:58:35.713087Z","shell.execute_reply.started":"2023-09-30T08:58:33.826111Z","shell.execute_reply":"2023-09-30T08:58:35.711710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical = df_train.select_dtypes(include = \"object\").columns\nfor i in range(0, len(categorical)):\n    print(df_train[categorical[i]].value_counts())\n    print('****************************************\\n')","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2023-09-30T08:58:43.095260Z","iopub.execute_input":"2023-09-30T08:58:43.095762Z","iopub.status.idle":"2023-09-30T08:58:43.794184Z","shell.execute_reply.started":"2023-09-30T08:58:43.095723Z","shell.execute_reply":"2023-09-30T08:58:43.792495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(columns=['S_2'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:53.087426Z","iopub.execute_input":"2023-09-30T08:58:53.087910Z","iopub.status.idle":"2023-09-30T08:58:54.391581Z","shell.execute_reply.started":"2023-09-30T08:58:53.087872Z","shell.execute_reply":"2023-09-30T08:58:54.390619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.drop(columns=['S_2'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:55.216990Z","iopub.execute_input":"2023-09-30T08:58:55.217440Z","iopub.status.idle":"2023-09-30T08:58:57.919528Z","shell.execute_reply.started":"2023-09-30T08:58:55.217403Z","shell.execute_reply":"2023-09-30T08:58:57.918122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D_63 = {'CO':0, 'CR':1, 'CL':2, 'XZ':3, 'XM':4, 'XL':5}\ndf_train['D_63'].replace(D_63, inplace=True)\ndf_test['D_63'].replace(D_63, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T08:58:58.352922Z","iopub.execute_input":"2023-09-30T08:58:58.353373Z","iopub.status.idle":"2023-09-30T08:59:04.394480Z","shell.execute_reply.started":"2023-09-30T08:58:58.353335Z","shell.execute_reply":"2023-09-30T08:59:04.393128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data visualization","metadata":{}},{"cell_type":"code","source":"corrmat = df_train.corr()\nf, ax = plt.subplots(figsize=(15, 12))\ncols = corrmat.nlargest(15, 'target')['target'].index\ncm = np.corrcoef(df_train[cols].values.T)\nsns.set(font_scale=1.5)\nhm = sns.heatmap(cm, cbar=True, annot=True, square=True, fmt='.2f', annot_kws={'size': 10},\n                 yticklabels=cols.values, xticklabels=cols.values)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:08:39.661226Z","iopub.execute_input":"2023-09-30T09:08:39.661785Z","iopub.status.idle":"2023-09-30T09:09:54.047389Z","shell.execute_reply.started":"2023-09-30T09:08:39.661745Z","shell.execute_reply":"2023-09-30T09:09:54.045720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = cols[1:]\ncols","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:13:21.712705Z","iopub.execute_input":"2023-09-30T09:13:21.713251Z","iopub.status.idle":"2023-09-30T09:13:21.725190Z","shell.execute_reply.started":"2023-09-30T09:13:21.713215Z","shell.execute_reply":"2023-09-30T09:13:21.723756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4,3))\nsns.countplot(x=df_train['target']);","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:13:33.219550Z","iopub.execute_input":"2023-09-30T09:13:33.221335Z","iopub.status.idle":"2023-09-30T09:13:34.101802Z","shell.execute_reply.started":"2023-09-30T09:13:33.221279Z","shell.execute_reply":"2023-09-30T09:13:34.100485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,15))\nfor i in range(len(cols[:9])):\n    plt.subplot(3,3, i+1) #the figure has 3 row, 3 columns, and this plot is the i-th plot.\n    sns.scatterplot(x=df_train[cols[i]], y=df_train['target'])\nplt.suptitle('Relation between target and nine important features')","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:13:41.940846Z","iopub.execute_input":"2023-09-30T09:13:41.941265Z","iopub.status.idle":"2023-09-30T09:16:58.530173Z","shell.execute_reply.started":"2023-09-30T09:13:41.941232Z","shell.execute_reply":"2023-09-30T09:16:58.527859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,15))\nfor i in range(len(cols[:9])):\n    plt.subplot(3,3, i+1) #the figure has 3 row, 3 columns, and this plot is the i-th plot.\n    sns.boxplot(x=df_train[cols[i]])\nplt.suptitle('Values for nine important features')","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:16:58.533195Z","iopub.execute_input":"2023-09-30T09:16:58.533648Z","iopub.status.idle":"2023-09-30T09:17:16.381797Z","shell.execute_reply.started":"2023-09-30T09:16:58.533605Z","shell.execute_reply":"2023-09-30T09:17:16.380133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Removing outliers**","metadata":{}},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['B_9'] > 15)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:21:47.248989Z","iopub.execute_input":"2023-09-30T09:21:47.249648Z","iopub.status.idle":"2023-09-30T09:21:50.561368Z","shell.execute_reply.started":"2023-09-30T09:21:47.249597Z","shell.execute_reply":"2023-09-30T09:21:50.560336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['D_75'] > 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:21:50.563039Z","iopub.execute_input":"2023-09-30T09:21:50.563950Z","iopub.status.idle":"2023-09-30T09:21:52.970830Z","shell.execute_reply.started":"2023-09-30T09:21:50.563913Z","shell.execute_reply":"2023-09-30T09:21:52.969502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['B_7'] < -0.5)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:21:52.972705Z","iopub.execute_input":"2023-09-30T09:21:52.973235Z","iopub.status.idle":"2023-09-30T09:21:55.209267Z","shell.execute_reply.started":"2023-09-30T09:21:52.973197Z","shell.execute_reply":"2023-09-30T09:21:55.207816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['B_23'] > 1.5)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:21:55.213226Z","iopub.execute_input":"2023-09-30T09:21:55.213834Z","iopub.status.idle":"2023-09-30T09:21:57.445239Z","shell.execute_reply.started":"2023-09-30T09:21:55.213778Z","shell.execute_reply":"2023-09-30T09:21:57.443903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['B_4'] > 4)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:21:57.446943Z","iopub.execute_input":"2023-09-30T09:21:57.447309Z","iopub.status.idle":"2023-09-30T09:21:59.574988Z","shell.execute_reply.started":"2023-09-30T09:21:57.447276Z","shell.execute_reply":"2023-09-30T09:21:59.573609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['B_1'] < -0.5)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:21:59.576685Z","iopub.execute_input":"2023-09-30T09:21:59.577026Z","iopub.status.idle":"2023-09-30T09:22:01.816984Z","shell.execute_reply.started":"2023-09-30T09:21:59.576998Z","shell.execute_reply":"2023-09-30T09:22:01.815442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['B_11'] > 1.6)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:22:01.818740Z","iopub.execute_input":"2023-09-30T09:22:01.819411Z","iopub.status.idle":"2023-09-30T09:22:03.959166Z","shell.execute_reply.started":"2023-09-30T09:22:01.819376Z","shell.execute_reply":"2023-09-30T09:22:03.957816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.drop(df_train[(df_train['R_1'] > 2.5)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:22:03.962243Z","iopub.execute_input":"2023-09-30T09:22:03.962957Z","iopub.status.idle":"2023-09-30T09:22:06.095296Z","shell.execute_reply.started":"2023-09-30T09:22:03.962916Z","shell.execute_reply":"2023-09-30T09:22:06.093874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Balancing for data","metadata":{}},{"cell_type":"code","source":"df_majority_0 = df_train[(df_train['target']==0)] \ndf_minority_1 = df_train[(df_train['target']==1)] \n\ndf_minority_upsampled = resample(df_minority_1, \n                                 replace=True,    \n                                 n_samples= len(df_majority_0), \n                                 random_state=44) \n\ndf_upsampled = pd.concat([df_minority_upsampled, df_majority_0])","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:23:04.855380Z","iopub.execute_input":"2023-09-30T09:23:04.856842Z","iopub.status.idle":"2023-09-30T09:23:16.739000Z","shell.execute_reply.started":"2023-09-30T09:23:04.856769Z","shell.execute_reply":"2023-09-30T09:23:16.737385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(4,3))\nsns.countplot(x=df_upsampled['target']);","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:23:16.741791Z","iopub.execute_input":"2023-09-30T09:23:16.742295Z","iopub.status.idle":"2023-09-30T09:23:18.898796Z","shell.execute_reply.started":"2023-09-30T09:23:16.742237Z","shell.execute_reply":"2023-09-30T09:23:18.897267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df_upsampled[cols]\ny = df_upsampled['target']","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:23:21.840153Z","iopub.execute_input":"2023-09-30T09:23:21.840626Z","iopub.status.idle":"2023-09-30T09:23:27.975392Z","shell.execute_reply.started":"2023-09-30T09:23:21.840590Z","shell.execute_reply":"2023-09-30T09:23:27.974360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Modeling stage","metadata":{}},{"cell_type":"code","source":"X_train, X_val_test, y_train, y_val_test = train_test_split(X, y, train_size=0.98, shuffle=True, random_state=100)\nX_val, X_test, y_val, y_test = train_test_split(X_val_test, y_val_test, train_size=0.5,shuffle=True,random_state=100)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:23:54.591018Z","iopub.execute_input":"2023-09-30T09:23:54.591521Z","iopub.status.idle":"2023-09-30T09:23:58.676397Z","shell.execute_reply.started":"2023-09-30T09:23:54.591482Z","shell.execute_reply":"2023-09-30T09:23:58.675083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**LogisticRegressionModel**","metadata":{}},{"cell_type":"code","source":"LogisticRegressionModel = LogisticRegression(penalty='l2',solver='sag',C=3.0,random_state=44)\nLogisticRegressionModel.fit(X_train, y_train)\n\n#Calculating Details\nprint('LogisticRegressionModel Train Score is : ' , LogisticRegressionModel.score(X_train, y_train))\nprint('LogisticRegressionModel Test Score is : ' , LogisticRegressionModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:24:02.224405Z","iopub.execute_input":"2023-09-30T09:24:02.224858Z","iopub.status.idle":"2023-09-30T09:32:01.064114Z","shell.execute_reply.started":"2023-09-30T09:24:02.224823Z","shell.execute_reply":"2023-09-30T09:32:01.057889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CrossValidateValues1 = cross_val_score(LogisticRegressionModel, X_val, y_val, cv=5)\n\n# Showing Results\nprint('Validation Score Value : ', CrossValidateValues1)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:32:01.071026Z","iopub.execute_input":"2023-09-30T09:32:01.071861Z","iopub.status.idle":"2023-09-30T09:32:14.257531Z","shell.execute_reply.started":"2023-09-30T09:32:01.071791Z","shell.execute_reply":"2023-09-30T09:32:14.252782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = LogisticRegressionModel.predict(X_test)\n\nplt.figure(figsize=(4,3))\nCM = confusion_matrix(y_test, y_pred)\nsns.heatmap(CM, center=True)\nplt.show()\n\nprint('Confusion Matrix is\\n', CM)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:35:00.930186Z","iopub.execute_input":"2023-09-30T09:35:00.930818Z","iopub.status.idle":"2023-09-30T09:35:01.261889Z","shell.execute_reply.started":"2023-09-30T09:35:00.930780Z","shell.execute_reply":"2023-09-30T09:35:01.260035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_test, y_pred))\nprint(accuracy_score(y_test, y_pred))","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:35:05.090233Z","iopub.execute_input":"2023-09-30T09:35:05.091024Z","iopub.status.idle":"2023-09-30T09:35:05.265140Z","shell.execute_reply.started":"2023-09-30T09:35:05.090986Z","shell.execute_reply":"2023-09-30T09:35:05.263659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**DecisionTreeClassifierModel**","metadata":{}},{"cell_type":"code","source":"DecisionTreeClassifierModel = DecisionTreeClassifier(criterion='entropy',max_depth=10,random_state=44)\nDecisionTreeClassifierModel.fit(X_train, y_train)\n\n#Calculating Details\nprint('DecisionTreeClassifierModel Train Score is : ' , DecisionTreeClassifierModel.score(X_train, y_train))\nprint('DecisionTreeClassifierModel Test Score is : ' , DecisionTreeClassifierModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:42:38.818433Z","iopub.execute_input":"2023-09-30T09:42:38.818937Z","iopub.status.idle":"2023-09-30T09:49:15.246129Z","shell.execute_reply.started":"2023-09-30T09:42:38.818900Z","shell.execute_reply":"2023-09-30T09:49:15.243480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CrossValidateValues2 = cross_val_score(DecisionTreeClassifierModel, X_val, y_val, cv=5)\n\n# Showing Results\nprint('Validation Score Value : ', CrossValidateValues2)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:49:15.248971Z","iopub.execute_input":"2023-09-30T09:49:15.249717Z","iopub.status.idle":"2023-09-30T09:49:23.917410Z","shell.execute_reply.started":"2023-09-30T09:49:15.249673Z","shell.execute_reply":"2023-09-30T09:49:23.916354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_DT = DecisionTreeClassifierModel.predict(X_test)\n\nplt.figure(figsize=(4,3))\n\nCM_DT = confusion_matrix(y_test, y_pred_DT)\nsns.heatmap(CM_DT, center=True)\nplt.show()\n\nprint('Confusion Matrix is\\n', CM_DT)","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:49:23.919156Z","iopub.execute_input":"2023-09-30T09:49:23.919875Z","iopub.status.idle":"2023-09-30T09:49:24.179067Z","shell.execute_reply.started":"2023-09-30T09:49:23.919837Z","shell.execute_reply":"2023-09-30T09:49:24.177753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_test, y_pred_DT))\nprint(accuracy_score(y_test, y_pred_DT))","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:50:34.199063Z","iopub.execute_input":"2023-09-30T09:50:34.199641Z","iopub.status.idle":"2023-09-30T09:50:34.380679Z","shell.execute_reply.started":"2023-09-30T09:50:34.199600Z","shell.execute_reply":"2023-09-30T09:50:34.378735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**XGBClassifierModel**","metadata":{}},{"cell_type":"code","source":"XGBClassifierModel = XGBClassifier(n_estimators=100, max_depth=15, eta=0.01, subsample=0.6, colsample_bytree=0.8) \nXGBClassifierModel.fit(X_train, y_train)\n\n#Calculating Details\nprint('XGBClassifierModel Train Score is : ' , XGBClassifierModel.score(X_train, y_train))\nprint('XGBClassifierModel Test Score is : ' , XGBClassifierModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2023-09-30T09:50:43.236714Z","iopub.execute_input":"2023-09-30T09:50:43.238083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"CrossValidateValues3 = cross_val_score(XGBClassifierModel, X_val, y_val, cv=5)\n\n# Showing Results\nprint('Validation Score Value : ', CrossValidateValues3)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_x = XGBClassifierModel.predict(X_test)\nCM_x = confusion_matrix(y_test, y_pred_x)\n\nplt.figure(figsize=(4,3))\nsns.heatmap(CM_x, center=True)\nplt.show()\n\nprint('Confusion Matrix is\\n', CM_x)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(classification_report(y_test, y_pred_x))\nprint(accuracy_score(y_test, y_pred_x))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Save the model and names of columns","metadata":{}},{"cell_type":"code","source":"import joblib\n\njoblib.dump(XGBClassifierModel, 'default_prediction_model.pkl')\nprint(\"Models dumped!\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_columns = list(X.columns)\njoblib.dump(model_columns, 'default_prediction_columns.pkl')\nprint(\"Models columns dumped!\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Submission**","metadata":{}},{"cell_type":"code","source":"#x_test = df_test[cols]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_pred_gbr = LogisticRegressionModel.predict(x_test)\n#y_pred_rf = RandomForestRegressorModel.predict(x_test)\n#y_pred_x = XGBClassifierModel.predict(x_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#submission = df_test[[\"customer_ID\"]] \n#submission[\"prediction\"] = y_pred_x\n#submission.to_csv('output.csv', index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}