{"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 os,shutil\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-12-12T17:12:14.747776Z","iopub.execute_input":"2022-12-12T17:12:14.748630Z","iopub.status.idle":"2022-12-12T17:12:14.774536Z","shell.execute_reply.started":"2022-12-12T17:12:14.748527Z","shell.execute_reply":"2022-12-12T17:12:14.773282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntrain = pd.read_parquet(\"../input/amex-data-integer-dtypes-parquet-format/train.parquet\")\ntrain_labels = pd.read_csv(\"../input/amex-default-prediction/train_labels.csv\")\ntrain = train.merge(train_labels,how=\"inner\",on=\"customer_ID\")","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:12:14.776837Z","iopub.execute_input":"2022-12-12T17:12:14.777660Z","iopub.status.idle":"2022-12-12T17:15:03.352423Z","shell.execute_reply.started":"2022-12-12T17:12:14.777619Z","shell.execute_reply":"2022-12-12T17:15:03.351074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nlab = LabelEncoder()\ntrain['customer_ID']= lab.fit_transform(train['customer_ID'])","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:03.354022Z","iopub.execute_input":"2022-12-12T17:15:03.354560Z","iopub.status.idle":"2022-12-12T17:15:07.084730Z","shell.execute_reply.started":"2022-12-12T17:15:03.354504Z","shell.execute_reply":"2022-12-12T17:15:07.083347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.groupby('customer_ID').tail(1).set_index('customer_ID')","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:07.088754Z","iopub.execute_input":"2022-12-12T17:15:07.089269Z","iopub.status.idle":"2022-12-12T17:15:10.120329Z","shell.execute_reply.started":"2022-12-12T17:15:07.089222Z","shell.execute_reply":"2022-12-12T17:15:10.119285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntest = pd.read_parquet(\"../input/amex-data-integer-dtypes-parquet-format/test.parquet\")","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:10.121453Z","iopub.execute_input":"2022-12-12T17:15:10.122073Z","iopub.status.idle":"2022-12-12T17:15:46.915306Z","shell.execute_reply.started":"2022-12-12T17:15:10.122038Z","shell.execute_reply":"2022-12-12T17:15:46.914212Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['customer_ID']= lab.fit_transform(test['customer_ID'])","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:46.917283Z","iopub.execute_input":"2022-12-12T17:15:46.918506Z","iopub.status.idle":"2022-12-12T17:15:52.831739Z","shell.execute_reply.started":"2022-12-12T17:15:46.918457Z","shell.execute_reply":"2022-12-12T17:15:52.830475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.groupby('customer_ID').tail(1).set_index('customer_ID')","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:52.833483Z","iopub.execute_input":"2022-12-12T17:15:52.833866Z","iopub.status.idle":"2022-12-12T17:15:54.831009Z","shell.execute_reply.started":"2022-12-12T17:15:52.833834Z","shell.execute_reply":"2022-12-12T17:15:54.829507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = train.target\nX = train.drop([\"target\",\"S_2\",'D_103'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:54.832793Z","iopub.execute_input":"2022-12-12T17:15:54.833625Z","iopub.status.idle":"2022-12-12T17:15:55.671466Z","shell.execute_reply.started":"2022-12-12T17:15:54.833585Z","shell.execute_reply":"2022-12-12T17:15:55.670532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntest = test.drop([\"S_2\",'D_103'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:55.672922Z","iopub.execute_input":"2022-12-12T17:15:55.673535Z","iopub.status.idle":"2022-12-12T17:15:56.130021Z","shell.execute_reply.started":"2022-12-12T17:15:55.673501Z","shell.execute_reply":"2022-12-12T17:15:56.129170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = X.fillna(-123)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:56.133581Z","iopub.execute_input":"2022-12-12T17:15:56.134202Z","iopub.status.idle":"2022-12-12T17:15:56.307161Z","shell.execute_reply.started":"2022-12-12T17:15:56.134169Z","shell.execute_reply":"2022-12-12T17:15:56.305847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.fillna(-123)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:56.308973Z","iopub.execute_input":"2022-12-12T17:15:56.309515Z","iopub.status.idle":"2022-12-12T17:15:56.644868Z","shell.execute_reply.started":"2022-12-12T17:15:56.309464Z","shell.execute_reply":"2022-12-12T17:15:56.643656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_cols =['B_30', 'B_38', 'D_63', 'D_64', 'D_66', 'D_68', 'D_114', 'D_116', 'D_117', 'D_120', 'D_126']\nnum_cols = [col for col in X.columns if col not in cat_cols ]","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:56.646343Z","iopub.execute_input":"2022-12-12T17:15:56.647256Z","iopub.status.idle":"2022-12-12T17:15:56.652053Z","shell.execute_reply.started":"2022-12-12T17:15:56.647213Z","shell.execute_reply":"2022-12-12T17:15:56.651076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D_n_cols = [col for col in num_cols if col.startswith(\"D\")]\nS_n_cols = [col for col in num_cols if col.startswith(\"S\")]\nP_n_cols = [col for col in num_cols if col.startswith(\"P\")]\nB_n_cols = [col for col in num_cols if col.startswith(\"B\")]\nR_n_cols = [col for col in num_cols if col.startswith(\"R\")]\nD_c_cols = [col for col in cat_cols if col.startswith(\"D\")]\nB_c_cols = [col for col in cat_cols if col.startswith(\"B\")] ","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:56.653093Z","iopub.execute_input":"2022-12-12T17:15:56.654165Z","iopub.status.idle":"2022-12-12T17:15:56.667056Z","shell.execute_reply.started":"2022-12-12T17:15:56.654127Z","shell.execute_reply":"2022-12-12T17:15:56.665825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"WD = 0.189734\nWS = -0.161529\nWP = -0.035248\nWB = 0.482908\nWR = 0.048839","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:56.669008Z","iopub.execute_input":"2022-12-12T17:15:56.669676Z","iopub.status.idle":"2022-12-12T17:15:56.679490Z","shell.execute_reply.started":"2022-12-12T17:15:56.669641Z","shell.execute_reply":"2022-12-12T17:15:56.678374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nX[\"D_mean\"]=X[D_n_cols].mean(axis=1)\nX[\"S_mean\"]=X[S_n_cols].mean(axis=1)\nX[\"P_mean\"]=X[P_n_cols].mean(axis=1)\nX[\"B_mean\"]=X[B_n_cols].mean(axis=1)\nX[\"R_mean\"]=X[R_n_cols].mean(axis=1)\n\nX['weight_mean'] = X['D_mean']* WD +  X[\"S_mean\"]* WS  + X[\"P_mean\"] * WP + X[\"B_mean\"]* WB + X[\"R_mean\"]*WR","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:56.681241Z","iopub.execute_input":"2022-12-12T17:15:56.682070Z","iopub.status.idle":"2022-12-12T17:15:57.507265Z","shell.execute_reply.started":"2022-12-12T17:15:56.682021Z","shell.execute_reply":"2022-12-12T17:15:57.505996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X['weight_co_square_B']=X[\"B_mean\"] * (WB**2)\nX['weight_co_square_R']=X[\"R_mean\"] * (WR**2)\nX['weight_co_square_D']=X[\"D_mean\"] * (WD**2)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:57.508793Z","iopub.execute_input":"2022-12-12T17:15:57.509208Z","iopub.status.idle":"2022-12-12T17:15:57.518694Z","shell.execute_reply.started":"2022-12-12T17:15:57.509176Z","shell.execute_reply":"2022-12-12T17:15:57.517561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntest[\"D_mean\"]=test[D_n_cols].mean(axis=1)\ntest[\"S_mean\"]=test[S_n_cols].mean(axis=1)\ntest[\"P_mean\"]=test[P_n_cols].mean(axis=1)\ntest[\"B_mean\"]=test[B_n_cols].mean(axis=1)\ntest[\"R_mean\"]=test[R_n_cols].mean(axis=1)\n\ntest['weight_mean'] = test['D_mean']* WD +  test[\"S_mean\"]* WS  + test[\"P_mean\"] * WP + test[\"B_mean\"]* WB + test[\"R_mean\"]*WR\n\ntest['weight_co_square_B']=test[\"B_mean\"] * (WB**2)\ntest['weight_co_square_R']=test[\"R_mean\"] * (WR**2)\ntest['weight_co_square_D']=test[\"D_mean\"] * (WD**2)\n\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:57.520188Z","iopub.execute_input":"2022-12-12T17:15:57.520785Z","iopub.status.idle":"2022-12-12T17:15:59.267722Z","shell.execute_reply.started":"2022-12-12T17:15:57.520730Z","shell.execute_reply":"2022-12-12T17:15:59.266386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:59.268941Z","iopub.execute_input":"2022-12-12T17:15:59.269870Z","iopub.status.idle":"2022-12-12T17:15:59.277426Z","shell.execute_reply.started":"2022-12-12T17:15:59.269829Z","shell.execute_reply":"2022-12-12T17:15:59.275859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nfrom sklearn.preprocessing import OrdinalEncoder\nordinal_encoder = OrdinalEncoder()\n\nX[cat_cols]= ordinal_encoder.fit_transform(X[cat_cols])","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:59.278721Z","iopub.execute_input":"2022-12-12T17:15:59.279113Z","iopub.status.idle":"2022-12-12T17:15:59.888113Z","shell.execute_reply.started":"2022-12-12T17:15:59.279082Z","shell.execute_reply":"2022-12-12T17:15:59.886893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test[cat_cols] = ordinal_encoder.transform(test[cat_cols])","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:15:59.889677Z","iopub.execute_input":"2022-12-12T17:15:59.890292Z","iopub.status.idle":"2022-12-12T17:16:00.875270Z","shell.execute_reply.started":"2022-12-12T17:15:59.890256Z","shell.execute_reply":"2022-12-12T17:16:00.874185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder,MinMaxScaler,OrdinalEncoder\nscaler = MinMaxScaler()\n\n\nX = scaler.fit_transform(X)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:00.876568Z","iopub.execute_input":"2022-12-12T17:16:00.877031Z","iopub.status.idle":"2022-12-12T17:16:02.026517Z","shell.execute_reply.started":"2022-12-12T17:16:00.876973Z","shell.execute_reply":"2022-12-12T17:16:02.025116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = scaler.fit_transform(test)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:02.028570Z","iopub.execute_input":"2022-12-12T17:16:02.030380Z","iopub.status.idle":"2022-12-12T17:16:04.259364Z","shell.execute_reply.started":"2022-12-12T17:16:02.030316Z","shell.execute_reply":"2022-12-12T17:16:04.258268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:04.260817Z","iopub.execute_input":"2022-12-12T17:16:04.261163Z","iopub.status.idle":"2022-12-12T17:16:04.319365Z","shell.execute_reply.started":"2022-12-12T17:16:04.261134Z","shell.execute_reply":"2022-12-12T17:16:04.318383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = np.array(X)\ny = np.array(y)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:04.321228Z","iopub.execute_input":"2022-12-12T17:16:04.321762Z","iopub.status.idle":"2022-12-12T17:16:04.611107Z","shell.execute_reply.started":"2022-12-12T17:16:04.321718Z","shell.execute_reply":"2022-12-12T17:16:04.610130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = np.array(test)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:04.612396Z","iopub.execute_input":"2022-12-12T17:16:04.612818Z","iopub.status.idle":"2022-12-12T17:16:05.147704Z","shell.execute_reply.started":"2022-12-12T17:16:04.612779Z","shell.execute_reply":"2022-12-12T17:16:05.146644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = X.reshape(-1,14,14,1)\n\nprint(\"x_train shape: \",X.shape)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:05.149001Z","iopub.execute_input":"2022-12-12T17:16:05.149356Z","iopub.status.idle":"2022-12-12T17:16:05.155066Z","shell.execute_reply.started":"2022-12-12T17:16:05.149325Z","shell.execute_reply":"2022-12-12T17:16:05.154034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.reshape(-1,14,14,1)\nprint(\"test shape: \",test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:05.156506Z","iopub.execute_input":"2022-12-12T17:16:05.156861Z","iopub.status.idle":"2022-12-12T17:16:05.168931Z","shell.execute_reply.started":"2022-12-12T17:16:05.156831Z","shell.execute_reply":"2022-12-12T17:16:05.167817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:05.175445Z","iopub.execute_input":"2022-12-12T17:16:05.175871Z","iopub.status.idle":"2022-12-12T17:16:11.748136Z","shell.execute_reply.started":"2022-12-12T17:16:05.175837Z","shell.execute_reply":"2022-12-12T17:16:11.747200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(X[0])","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:11.749677Z","iopub.execute_input":"2022-12-12T17:16:11.750617Z","iopub.status.idle":"2022-12-12T17:16:11.960202Z","shell.execute_reply.started":"2022-12-12T17:16:11.750579Z","shell.execute_reply":"2022-12-12T17:16:11.958701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, Y_train, Y_val = train_test_split(X, y, test_size = 0.1, random_state=2,stratify=y)\nprint(\"x_train shape\",X_train.shape)\nprint(\"x_test shape\",X_val.shape)\nprint(\"y_train shape\",Y_train.shape)\nprint(\"y_test shape\",Y_val.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:11.962167Z","iopub.execute_input":"2022-12-12T17:16:11.962677Z","iopub.status.idle":"2022-12-12T17:16:13.238406Z","shell.execute_reply.started":"2022-12-12T17:16:11.962633Z","shell.execute_reply":"2022-12-12T17:16:13.237235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf \nfrom tensorflow import keras\n\nfrom keras import models\nfrom keras import layers\n\nfrom keras.models import Sequential\n\n\nimport matplotlib.pyplot as plt\nfrom keras import optimizers\nfrom sklearn.model_selection import train_test_split\n\n\n\n\nimport matplotlib.pylab as plt\n\nimport tensorflow as tf\nimport tensorflow_hub as hub\n\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.models import Sequential\n\nimport tensorflow as tf\nfrom tensorflow import keras\nfrom tensorflow.keras.models import Sequential\n\nfrom tensorflow.keras import layers,callbacks\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:13.239894Z","iopub.execute_input":"2022-12-12T17:16:13.240256Z","iopub.status.idle":"2022-12-12T17:16:13.609177Z","shell.execute_reply.started":"2022-12-12T17:16:13.240226Z","shell.execute_reply":"2022-12-12T17:16:13.608051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"feature_extractor_model = \"https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4\"\n\npretrained_model_without_top_layer = hub.KerasLayer(\n    feature_extractor_model, input_shape=(14, 14, 1), trainable=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:13.610549Z","iopub.execute_input":"2022-12-12T17:16:13.610907Z","iopub.status.idle":"2022-12-12T17:16:16.788800Z","shell.execute_reply.started":"2022-12-12T17:16:13.610876Z","shell.execute_reply":"2022-12-12T17:16:16.787921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nmodel = models.Sequential()\n\nhub.KerasLayer(\n    feature_extractor_model, input_shape=(14, 14, 1), trainable=False)\n\nmodel.add(layers.Flatten())\nmodel.add(layers.Dense(512))\nmodel.add(layers.Dense(1,activation='sigmoid'))\n\n","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:16.790340Z","iopub.execute_input":"2022-12-12T17:16:16.791596Z","iopub.status.idle":"2022-12-12T17:16:18.276381Z","shell.execute_reply.started":"2022-12-12T17:16:16.791544Z","shell.execute_reply":"2022-12-12T17:16:18.275268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stopping = callbacks.EarlyStopping(\n                 min_delta=0.001,\n                 patience=20,\n                 restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:18.277710Z","iopub.execute_input":"2022-12-12T17:16:18.278169Z","iopub.status.idle":"2022-12-12T17:16:18.284703Z","shell.execute_reply.started":"2022-12-12T17:16:18.278128Z","shell.execute_reply":"2022-12-12T17:16:18.283637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer= tf.keras.optimizers.Adam(\n    learning_rate=0.0054166898758110146),\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:18.286123Z","iopub.execute_input":"2022-12-12T17:16:18.286488Z","iopub.status.idle":"2022-12-12T17:16:18.311491Z","shell.execute_reply.started":"2022-12-12T17:16:18.286458Z","shell.execute_reply":"2022-12-12T17:16:18.310114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nhistory = model.fit(X_train,Y_train,validation_data=(X_val,Y_val),\n                    batch_size=1000,epochs=30,callbacks=[early_stopping],verbose=1)\n\nhistory_df = pd.DataFrame(history.history)\nhistory_df.loc[:, ['loss', 'val_loss']].plot();\nprint(\"Minimum validation loss: {}\".format(history_df['val_loss'].min()))","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:16:18.312958Z","iopub.execute_input":"2022-12-12T17:16:18.313412Z","iopub.status.idle":"2022-12-12T17:18:41.569395Z","shell.execute_reply.started":"2022-12-12T17:16:18.313378Z","shell.execute_reply":"2022-12-12T17:18:41.568267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df.loc[:, ['accuracy', 'val_accuracy']].plot();\nprint(\"Maximum accuracy : {}\".format(history_df['val_accuracy'].max()))","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:18:41.573283Z","iopub.execute_input":"2022-12-12T17:18:41.573648Z","iopub.status.idle":"2022-12-12T17:18:41.789854Z","shell.execute_reply.started":"2022-12-12T17:18:41.573615Z","shell.execute_reply":"2022-12-12T17:18:41.788628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(X_val)\npred_te = predictions.round()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:18:41.791197Z","iopub.execute_input":"2022-12-12T17:18:41.791529Z","iopub.status.idle":"2022-12-12T17:18:43.243874Z","shell.execute_reply.started":"2022-12-12T17:18:41.791485Z","shell.execute_reply":"2022-12-12T17:18:43.242825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import classification_report,confusion_matrix\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\ncm = confusion_matrix(Y_val,pred_te)\n\nplt.figure(figsize=(10,7))\n\nsns.heatmap(cm,annot=True,fmt='d')\n\nplt.xlabel('Predicted')\nplt.ylabel('Truth')","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:18:43.245226Z","iopub.execute_input":"2022-12-12T17:18:43.245561Z","iopub.status.idle":"2022-12-12T17:18:43.513652Z","shell.execute_reply.started":"2022-12-12T17:18:43.245532Z","shell.execute_reply":"2022-12-12T17:18:43.512278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cf = classification_report(Y_val,pred_te)\n\nprint(cf)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:18:43.517116Z","iopub.execute_input":"2022-12-12T17:18:43.517572Z","iopub.status.idle":"2022-12-12T17:18:43.623484Z","shell.execute_reply.started":"2022-12-12T17:18:43.517535Z","shell.execute_reply":"2022-12-12T17:18:43.622282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub = pd.read_csv('../input/amex-default-prediction/sample_submission.csv')\n\nsub.head","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:18:43.625282Z","iopub.execute_input":"2022-12-12T17:18:43.625653Z","iopub.status.idle":"2022-12-12T17:18:45.686129Z","shell.execute_reply.started":"2022-12-12T17:18:43.625621Z","shell.execute_reply":"2022-12-12T17:18:45.684929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred_test = model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:18:45.688049Z","iopub.execute_input":"2022-12-12T17:18:45.688508Z","iopub.status.idle":"2022-12-12T17:19:29.132698Z","shell.execute_reply.started":"2022-12-12T17:18:45.688466Z","shell.execute_reply":"2022-12-12T17:19:29.131398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub['prediction']=pred_test","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:19:29.135949Z","iopub.execute_input":"2022-12-12T17:19:29.136485Z","iopub.status.idle":"2022-12-12T17:19:29.143498Z","shell.execute_reply.started":"2022-12-12T17:19:29.136437Z","shell.execute_reply":"2022-12-12T17:19:29.142306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:19:29.145680Z","iopub.execute_input":"2022-12-12T17:19:29.146180Z","iopub.status.idle":"2022-12-12T17:19:29.164238Z","shell.execute_reply.started":"2022-12-12T17:19:29.146134Z","shell.execute_reply":"2022-12-12T17:19:29.163272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-12T17:19:29.165501Z","iopub.execute_input":"2022-12-12T17:19:29.166506Z","iopub.status.idle":"2022-12-12T17:19:32.000246Z","shell.execute_reply.started":"2022-12-12T17:19:29.166471Z","shell.execute_reply":"2022-12-12T17:19:31.999019Z"},"trusted":true},"execution_count":null,"outputs":[]}]}