{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":3362,"databundleVersionId":31148,"sourceType":"competition"}],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport gc\nimport pywt\nimport cupy\nimport optuna\nimport cv2 as cv\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nfrom zipfile import ZipFile\nfrom tqdm import tqdm\nfrom joblib import dump, load\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.svm import SVC\nfrom sklearn.decomposition import PCA\nfrom sklearn.linear_model import LogisticRegression\nfrom xgboost import XGBRFClassifier, XGBClassifier\nfrom sklearn.metrics import classification_report, accuracy_score\nfrom sklearn.model_selection import StratifiedKFold\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\n!pip install optuna_integration\nfrom optuna_integration import XGBoostPruningCallback","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-05-04T05:31:22.013475Z","iopub.execute_input":"2024-05-04T05:31:22.014201Z","iopub.status.idle":"2024-05-04T05:31:40.083849Z","shell.execute_reply.started":"2024-05-04T05:31:22.014166Z","shell.execute_reply":"2024-05-04T05:31:40.082613Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with ZipFile('/kaggle/input/dogs-vs-cats/train.zip','r') as train:\n    train.extractall('.')","metadata":{"execution":{"iopub.status.busy":"2024-05-04T05:31:43.042761Z","iopub.execute_input":"2024-05-04T05:31:43.043510Z","iopub.status.idle":"2024-05-04T05:31:52.466206Z","shell.execute_reply.started":"2024-05-04T05:31:43.043472Z","shell.execute_reply":"2024-05-04T05:31:52.465393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Saving all the filenames and encoding dog as 1 and cat as 0","metadata":{}},{"cell_type":"code","source":"filenames = os.listdir('train')\npet_labels = []\n\nfor file in filenames:\n    if file.split('.')[0] == 'cat':\n        pet_labels.append(0)\n    else:\n        pet_labels.append(1)\n        \nlabel_df = pd.DataFrame()\nlabel_df['filenames'] = filenames\nlabel_df['labels'] = pet_labels\nlabel_df.sample(5)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T05:31:53.227137Z","iopub.execute_input":"2024-05-04T05:31:53.227515Z","iopub.status.idle":"2024-05-04T05:31:53.300367Z","shell.execute_reply.started":"2024-05-04T05:31:53.227484Z","shell.execute_reply":"2024-05-04T05:31:53.299429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def resize(img, target_height=300, target_width=300):\n    '''\n    Function for maintaining aspect ratio without any distortions while downscaling the images.\n    The empty areas will be padded with black borders.\n    '''\n\n    height, width = img.shape[:2]\n\n    if height > width:\n        new_height = target_height\n        new_width = int((width * target_height) / height)\n    elif width > height:\n        new_width = target_width\n        new_height = int((height * target_width) / width)\n    else:\n        new_height = target_height\n        new_width = target_width\n\n    img_resize = cv.resize(img, (new_width, new_height), \n                           interpolation=cv.INTER_LANCZOS4)\n\n    top = bottom = left = right = 0\n    \n    if new_height < target_height:\n        padding_height = target_height - new_height\n        top = int(padding_height / 2)\n        bottom = padding_height - top\n    if new_width < target_width:\n        padding_width = target_width - new_width\n        left = int(padding_width / 2)\n        right = padding_width - left\n\n    img_resize = cv.copyMakeBorder(img_resize, top, bottom, left, right, \n                                   cv.BORDER_CONSTANT, value=(0, 0, 0))\n    \n    return img_resize","metadata":{"execution":{"iopub.status.busy":"2024-05-04T05:31:57.269920Z","iopub.execute_input":"2024-05-04T05:31:57.270255Z","iopub.status.idle":"2024-05-04T05:31:57.280366Z","shell.execute_reply.started":"2024-05-04T05:31:57.270230Z","shell.execute_reply":"2024-05-04T05:31:57.279254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Example\npath = '/kaggle/working/train/cat.8.jpg'\nimg_src = cv.imread(path)\nimg = resize(img_src, 330, 330)\nplt.imshow(img)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-04T05:32:02.113883Z","iopub.execute_input":"2024-05-04T05:32:02.114275Z","iopub.status.idle":"2024-05-04T05:32:02.493522Z","shell.execute_reply.started":"2024-05-04T05:32:02.114234Z","shell.execute_reply":"2024-05-04T05:32:02.492589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Downscaling all the images to 15x15 and flattening it\ntrain_path = '/kaggle/working/train/'\nnum_images = len(label_df)\nimg_resized = np.empty((num_images, 15*15*3))\n\nfor i,file in tqdm(enumerate(label_df['filenames']), total=num_images):\n    file_path = train_path + file\n    \n    img_src = cv.imread(file_path)\n    img_resized[i] = resize(img_src, 15, 15).flatten()","metadata":{"execution":{"iopub.status.busy":"2024-05-04T05:32:08.785871Z","iopub.execute_input":"2024-05-04T05:32:08.786255Z","iopub.status.idle":"2024-05-04T05:32:55.711958Z","shell.execute_reply.started":"2024-05-04T05:32:08.786207Z","shell.execute_reply":"2024-05-04T05:32:55.711001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Feature Extraction","metadata":{}},{"cell_type":"code","source":"# Using wavelet decomposition to extract components from the images like edges, textures and other patterns. \n# Removing low frequency data from it and reconstructing back the image.\nimg_wavelet = np.empty((num_images, 16*16))\n\nfor i,file in tqdm(enumerate(label_df['filenames']), total=num_images):\n    \n    gc.collect()\n    file_path = train_path + file\n    img_src = cv.imread(file_path)\n    img = cv.cvtColor(img_src, cv.COLOR_RGB2GRAY)\n    img = resize(img, 16, 16)\n    img = np.float32(img) / 255\n    coef = pywt.wavedec2(img, 'db30', level=5)\n    # Removing low frequency data (approximation coefficients) from the image\n    coef[0] *= 0\n    img = pywt.waverec2(coef, 'db30') * 255\n    img_wavelet[i] = np.uint8(img).flatten()","metadata":{"execution":{"iopub.status.busy":"2024-05-04T05:33:43.970769Z","iopub.execute_input":"2024-05-04T05:33:43.971141Z","iopub.status.idle":"2024-05-04T06:15:39.224683Z","shell.execute_reply.started":"2024-05-04T05:33:43.971114Z","shell.execute_reply":"2024-05-04T06:15:39.223839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Example image\npath = '/kaggle/working/train/cat.8.jpg'\nimg_src = cv.imread(path)\nimg = cv.cvtColor(img_src, cv.COLOR_RGB2GRAY)\nimg = resize(img, 330, 330)\nimg = np.float32(img) / 255\ncoef = pywt.wavedec2(img, 'db30', level=5)\ncoef[0] *= 0\nimg = pywt.waverec2(coef, 'db30') * 255\nimg = np.uint8(img)\nplt.imshow(img, cmap='gray')","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:15:43.355834Z","iopub.execute_input":"2024-05-04T06:15:43.356175Z","iopub.status.idle":"2024-05-04T06:15:43.731418Z","shell.execute_reply.started":"2024-05-04T06:15:43.356151Z","shell.execute_reply":"2024-05-04T06:15:43.730565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"For every image we'll stack together the downscaled image array and the wavelet transformed image array together. The resultant array will be used for training.","metadata":{}},{"cell_type":"code","source":"img_wavelet.shape, img_resized.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:15:48.042155Z","iopub.execute_input":"2024-05-04T06:15:48.042509Z","iopub.status.idle":"2024-05-04T06:15:48.048444Z","shell.execute_reply.started":"2024-05-04T06:15:48.042481Z","shell.execute_reply":"2024-05-04T06:15:48.047530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Stacking both the arrays together\nimg_data = np.hstack((img_resized,img_wavelet))\ny = label_df['labels'].values\nimg_data.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:15:50.966378Z","iopub.execute_input":"2024-05-04T06:15:50.966726Z","iopub.status.idle":"2024-05-04T06:15:51.035048Z","shell.execute_reply.started":"2024-05-04T06:15:50.966699Z","shell.execute_reply":"2024-05-04T06:15:51.034030Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Model Training","metadata":{}},{"cell_type":"code","source":"# Train test split using stratify\nX_train, X_test, y_train, y_test = train_test_split(img_data, y, train_size=0.80, random_state=300, stratify=y)\n\n# Saving the files\nnp.savez('train_test.npz', X_train=X_train, y_train=y_train, X_test=X_test, y_test=y_test)\n\nX_train.shape, X_test.shape, y_train.shape, y_test.shape","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:15:54.689973Z","iopub.execute_input":"2024-05-04T06:15:54.690558Z","iopub.status.idle":"2024-05-04T06:15:55.070818Z","shell.execute_reply.started":"2024-05-04T06:15:54.690531Z","shell.execute_reply":"2024-05-04T06:15:55.069698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_test = np.load('/kaggle/working/train_test.npz')\n# X_train = train_test['X_train']\n# X_test = train_test['X_test']\n# y_train = train_test['y_train']\n# y_test = train_test['y_test']","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:16:00.496494Z","iopub.execute_input":"2024-05-04T06:16:00.497242Z","iopub.status.idle":"2024-05-04T06:16:00.501216Z","shell.execute_reply.started":"2024-05-04T06:16:00.497209Z","shell.execute_reply":"2024-05-04T06:16:00.500201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# The final array is in 0-255 range so standardizing it\nscaler = StandardScaler()\nX_train_stzd = scaler.fit_transform(X_train)\nX_test_stzd = scaler.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:16:07.353788Z","iopub.execute_input":"2024-05-04T06:16:07.354149Z","iopub.status.idle":"2024-05-04T06:16:07.644264Z","shell.execute_reply.started":"2024-05-04T06:16:07.354120Z","shell.execute_reply":"2024-05-04T06:16:07.643413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# For using GPU during training\nX_train_stzd_gpu = cupy.array(X_train_stzd)\nX_test_stzd_gpu = cupy.array(X_test_stzd)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T04:38:58.156974Z","iopub.execute_input":"2024-05-04T04:38:58.157310Z","iopub.status.idle":"2024-05-04T04:38:58.466600Z","shell.execute_reply.started":"2024-05-04T04:38:58.157283Z","shell.execute_reply":"2024-05-04T04:38:58.465778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# RandomForest from XGBoost\nxgrf = XGBRFClassifier(device='cuda',tree_method='hist')\nxgrf.fit(X_train_stzd_gpu, y_train)\n\ny_pred_xgrf = xgrf.predict(X_test_stzd_gpu)\nreport_xgrf = classification_report(y_test,y_pred_xgrf)\nprint(f'Classififcation Report (XGRF):\\n {report_xgrf}')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T01:30:31.996823Z","iopub.execute_input":"2024-05-03T01:30:31.997210Z","iopub.status.idle":"2024-05-03T01:30:33.603962Z","shell.execute_reply.started":"2024-05-03T01:30:31.997179Z","shell.execute_reply":"2024-05-03T01:30:33.603039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# For SVC, applying PCA first since training takes long time with SVC for high dimensional data\n# Choosing num of components that make up 99% of explained variance\npca = PCA(n_components=0.99)\nX_train_pca = pca.fit_transform(X_train_stzd)\nX_test_pca = pca.transform(X_test_stzd)\n\nsv = SVC()\nsv.fit(X_train_pca,y_train)\n\ny_test_pred_sv = sv.predict(X_test_pca)\nreport_sv = classification_report(y_test,y_test_pred_sv)\nprint(f'Classififcation Report (SVC):\\n {report_sv}')","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:36:55.515260Z","iopub.execute_input":"2024-05-04T06:36:55.515637Z","iopub.status.idle":"2024-05-04T06:41:07.331596Z","shell.execute_reply.started":"2024-05-04T06:36:55.515609Z","shell.execute_reply":"2024-05-04T06:41:07.330358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# XGBoost Classifier model\nxgbc = XGBClassifier(device='cuda',tree_method='hist')\nxgbc.fit(X_train_stzd_gpu,y_train)\n\ny_test_pred_xgbc = xgbc.predict(X_test_stzd_gpu)\nreport_xgbc = classification_report(y_test,y_test_pred_xgbc)\nprint(f'Classififcation Report (XGBClassifier):\\n {report_xgbc}')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T01:30:33.605528Z","iopub.execute_input":"2024-05-03T01:30:33.605997Z","iopub.status.idle":"2024-05-03T01:30:34.478602Z","shell.execute_reply.started":"2024-05-03T01:30:33.605961Z","shell.execute_reply":"2024-05-03T01:30:34.477527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Hyperparameter Tuning","metadata":{}},{"cell_type":"markdown","source":"Hyperparameter tuning XGboost Classifier model with Optuna","metadata":{}},{"cell_type":"code","source":"# Making a validation set for tuning\nX_train_xg, X_val_xg, y_train_xg, y_val_xg = train_test_split(X_train_stzd, y_train, test_size=0.20, \n                                                              random_state=300, stratify=y_train)\n\n# Storing both train and test in gpu\nX_train_xg_gpu = cupy.array(X_train_xg)\nX_val_xg_gpu = cupy.array(X_val_xg)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T04:49:04.433607Z","iopub.execute_input":"2024-05-04T04:49:04.434491Z","iopub.status.idle":"2024-05-04T04:49:04.596601Z","shell.execute_reply.started":"2024-05-04T04:49:04.434456Z","shell.execute_reply":"2024-05-04T04:49:04.595790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def objective(trial):\n    \n    pruning_callback = XGBoostPruningCallback(trial, 'validation_0-error')\n    \n    xgb_tuning=XGBClassifier(\n        n_estimators=trial.suggest_int('n_estimators', 50, 10000),\n        max_depth=trial.suggest_int('max_depth', 2, 70),\n        min_child_weight=trial.suggest_int('min_child_weight', 1, 20),\n        colsample_bytree=trial.suggest_float('colsample_bytree', 0.2, 1),\n        subsample=trial.suggest_float('subsample', 0.2, 1),\n        learning_rate=trial.suggest_float('learning_rate', 1e-4, 1, log=True),\n        reg_alpha=trial.suggest_float('reg_alpha',1e-2, 100, log=True),\n        reg_lambda=trial.suggest_float('reg_lambda',1e-2, 100, log=True),\n        objective='binary:logistic',\n        callbacks=[pruning_callback],\n        eval_metric='error',\n        device='cuda',\n        tree_method='hist',\n        n_jobs=-1\n    )\n    \n    gc.collect()\n    xgb_tuning.fit(X_train_xg_gpu, y_train_xg,\n                   eval_set=[(X_val_xg_gpu, y_val_xg)], \n                   verbose=False)\n    \n    y_val_xg_pred = xgb_tuning.predict(X_val_xg_gpu)\n    accuracy = accuracy_score(y_val_xg, y_val_xg_pred)\n    \n    return accuracy\n    \nstudy = optuna.create_study(direction='maximize',\n                            pruner=optuna.pruners.MedianPruner(n_warmup_steps=5),\n                            study_name='XGBClassifier Image Classification Tuning')\n\n# Will run for 150 trials or 3 hours, whichever happens first\nstudy.optimize(objective, n_trials=150, timeout=3*60*60)\ndump(study,'XGBClassifier_image_classifier_study.pkl')\n\nbest_params = study.best_trial.params","metadata":{"execution":{"iopub.status.busy":"2024-05-03T01:30:34.481426Z","iopub.execute_input":"2024-05-03T01:30:34.481683Z","iopub.status.idle":"2024-05-03T04:31:49.554205Z","shell.execute_reply.started":"2024-05-03T01:30:34.481660Z","shell.execute_reply":"2024-05-03T04:31:49.553405Z"},"scrolled":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('--'*45)\nprint('The best Hyperparameters are: ')\nfor key,value in best_params.items():\n    print(f'{key:>30s} : {value}')\nprint('--'*45)\nprint(f'{\"Best Accuracy (Val Set)\":>30s} : {study.best_value}')\nprint('=='*45)","metadata":{"execution":{"iopub.status.busy":"2024-05-03T04:38:46.951648Z","iopub.execute_input":"2024-05-03T04:38:46.952315Z","iopub.status.idle":"2024-05-03T04:38:46.975827Z","shell.execute_reply.started":"2024-05-03T04:38:46.952284Z","shell.execute_reply":"2024-05-03T04:38:46.974939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Eval metrics for test set\nxgbc = XGBClassifier(device='cuda', tree_method='hist', **best_params)\nxgbc.fit(X_train_stzd_gpu,y_train)\n\ny_test_pred_xgbc = xgbc.predict(X_test_stzd_gpu)\nreport_xgbc = classification_report(y_test,y_test_pred_xgbc)\nprint(f'Classififcation Report For Test Set (Tuned XGBClassifier Model):\\n {report_xgbc}')","metadata":{"execution":{"iopub.status.busy":"2024-05-03T04:41:30.035436Z","iopub.execute_input":"2024-05-03T04:41:30.036202Z","iopub.status.idle":"2024-05-03T04:42:55.528679Z","shell.execute_reply.started":"2024-05-03T04:41:30.036169Z","shell.execute_reply":"2024-05-03T04:42:55.527658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Best accuracy on test set is 71%","metadata":{}},{"cell_type":"markdown","source":"#### Predicting Kaggle Test Set","metadata":{}},{"cell_type":"code","source":"with ZipFile('/kaggle/input/dogs-vs-cats/test1.zip','r') as test:\n    test.extractall('.')","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:41:31.661328Z","iopub.execute_input":"2024-05-04T06:41:31.662028Z","iopub.status.idle":"2024-05-04T06:41:36.876513Z","shell.execute_reply.started":"2024-05-04T06:41:31.661997Z","shell.execute_reply":"2024-05-04T06:41:36.875728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id = []\nimage_paths = []\n\nfor file in os.listdir('test1'):\n    id.append(int(file.split('.')[0]))\n    image_paths.append('/kaggle/working/test1/' + file)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:41:42.976439Z","iopub.execute_input":"2024-05-04T06:41:42.976898Z","iopub.status.idle":"2024-05-04T06:41:43.001759Z","shell.execute_reply.started":"2024-05-04T06:41:42.976870Z","shell.execute_reply":"2024-05-04T06:41:43.001051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Submission = pd.DataFrame()\nSubmission['id'] = id\nSubmission['image_paths'] = image_paths\nSubmission.sample(5)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:41:51.771375Z","iopub.execute_input":"2024-05-04T06:41:51.771980Z","iopub.status.idle":"2024-05-04T06:41:51.796477Z","shell.execute_reply.started":"2024-05-04T06:41:51.771949Z","shell.execute_reply":"2024-05-04T06:41:51.795572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def test_preprocessor(image_paths, scaler):\n    '''\n    For applying all the preprocessing steps we had done for training\n    on the kaggle test data as well. Returns test image array.\n    '''\n    \n    num_images = len(image_paths)\n    img_resized = np.empty((num_images, 15*15*3))\n    img_wavelet = np.empty((num_images, 16*16))\n    \n    for i,image_path in tqdm(enumerate(image_paths), total=num_images):\n        # Downscaling\n        img_src = cv.imread(image_path)\n        img_resized[i] = resize(img_src, 15, 15).flatten()\n        # Wavelet Decompose\n        img = cv.cvtColor(img_src, cv.COLOR_RGB2GRAY)\n        img = resize(img, 16, 16)\n        img = np.float32(img) / 255\n        coef = pywt.wavedec2(img, 'db30', level=5)\n        coef[0] *= 0\n        img = pywt.waverec2(coef, 'db30') * 255\n        img_wavelet[i] = np.uint8(img).flatten()\n    # Concatenating\n    img_data = np.hstack((img_resized,img_wavelet))\n    # scaler transform\n    test_preprocessed = scaler.transform(img_data)\n    \n    return test_preprocessed","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:42:46.380441Z","iopub.execute_input":"2024-05-04T06:42:46.381201Z","iopub.status.idle":"2024-05-04T06:42:46.390261Z","shell.execute_reply.started":"2024-05-04T06:42:46.381170Z","shell.execute_reply":"2024-05-04T06:42:46.389199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_array = test_preprocessor(Submission['image_paths'], scaler)\ntest_array[:3]","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:43:28.634636Z","iopub.execute_input":"2024-05-04T06:43:28.635163Z","iopub.status.idle":"2024-05-04T06:45:37.887603Z","shell.execute_reply.started":"2024-05-04T06:43:28.635108Z","shell.execute_reply":"2024-05-04T06:45:37.886682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Kaggle test set predictions\nlabels = xgbc.predict(test_array)\n\n# Saving to dataframe\nSubmission['label'] = labels\n\n\nprint(Submission['label'].value_counts())\nSubmission['label'].value_counts().plot(kind='bar', color=['crimson','steelblue'])","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:45:54.470340Z","iopub.execute_input":"2024-05-04T06:45:54.471430Z","iopub.status.idle":"2024-05-04T06:45:55.339161Z","shell.execute_reply.started":"2024-05-04T06:45:54.471371Z","shell.execute_reply":"2024-05-04T06:45:55.338275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Submission[['id','label']].sort_values('id',ascending=True).to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-05-04T06:50:50.582281Z","iopub.execute_input":"2024-05-04T06:50:50.582902Z","iopub.status.idle":"2024-05-04T06:50:50.610821Z","shell.execute_reply.started":"2024-05-04T06:50:50.582863Z","shell.execute_reply":"2024-05-04T06:50:50.610026Z"},"trusted":true},"execution_count":null,"outputs":[]}]}