{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"},{"sourceId":34877,"sourceType":"datasetVersion","datasetId":27352}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# IMPORTS\nimport pandas as pd\nimport warnings","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:36.353558Z","iopub.execute_input":"2025-06-11T08:02:36.353825Z","iopub.status.idle":"2025-06-11T08:02:36.357991Z","shell.execute_reply.started":"2025-06-11T08:02:36.353806Z","shell.execute_reply":"2025-06-11T08:02:36.357208Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# WARNING SUPPRESSION (convenience)\nwarnings.filterwarnings('ignore')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:36.359481Z","iopub.execute_input":"2025-06-11T08:02:36.359777Z","iopub.status.idle":"2025-06-11T08:02:36.374221Z","shell.execute_reply.started":"2025-06-11T08:02:36.359752Z","shell.execute_reply":"2025-06-11T08:02:36.373429Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# LOADING ALL DATASETS\n\n# i. Mnist Dataset\nmnist_test = pd.read_csv(\"../input/mnist-in-csv/mnist_test.csv\")\nmnist_train = pd.read_csv(\"../input/mnist-in-csv/mnist_train.csv\")\n\n# ii. Competition Dataset\nsample_submission = pd.read_csv(\"../input/digit-recognizer/sample_submission.csv\")\ntest = pd.read_csv(\"../input/digit-recognizer/test.csv\")\ntrain = pd.read_csv(\"../input/digit-recognizer/train.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:36.374970Z","iopub.execute_input":"2025-06-11T08:02:36.375253Z","iopub.status.idle":"2025-06-11T08:02:43.964194Z","shell.execute_reply.started":"2025-06-11T08:02:36.375229Z","shell.execute_reply":"2025-06-11T08:02:43.963532Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# CREATING COMBINED DATASET FROM COMPETITION TEST AND TRAIN\n\n# i. Identifying data source\ntest['dataset'] = 'test'\ntrain['dataset'] = 'train'\n\n# ii. Combining datasets (excluding label column)\ndataset = pd.concat([train.drop('label', axis=1), test]).reset_index()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:43.965816Z","iopub.execute_input":"2025-06-11T08:02:43.966053Z","iopub.status.idle":"2025-06-11T08:02:44.433736Z","shell.execute_reply.started":"2025-06-11T08:02:43.966034Z","shell.execute_reply":"2025-06-11T08:02:44.432979Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ALIGN MINST-CSV DATASET TO MATCH COMPETITION FORMAT\n\n# i. MINST train + test dataset into single frame\nmnist = pd.concat([mnist_train, mnist_test]).reset_index(drop=True)\n\n# ii. Extracting labels before dropping\nlabels = mnist['label'].values\nmnist.drop('label', axis=1, inplace=True)\n\n# iii. Renaming MNIST columns to that of competition test columns\nmnist.columns = test.columns[:-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:44.434618Z","iopub.execute_input":"2025-06-11T08:02:44.434859Z","iopub.status.idle":"2025-06-11T08:02:44.855846Z","shell.execute_reply.started":"2025-06-11T08:02:44.434840Z","shell.execute_reply":"2025-06-11T08:02:44.855225Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# MATCHING MNIST IMAGES TO KAGGLE IMAGES USING PIXEL VALUES\n\n# i. Sorting by pixel value from MINST and competition datasets\nidx_mnist = mnist.sort_values(by=list(mnist.columns)).index\ndataset_sorted = dataset.sort_values(by=list(mnist.columns))\n\n# ii. Extraction of original indices from source\ndataset_from = dataset_sorted['dataset'].values\noriginal_idx = dataset_sorted['index'].values","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:44.856668Z","iopub.execute_input":"2025-06-11T08:02:44.856906Z","iopub.status.idle":"2025-06-11T08:02:47.345524Z","shell.execute_reply.started":"2025-06-11T08:02:44.856887Z","shell.execute_reply":"2025-06-11T08:02:47.344679Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# MAPPING MNIST LABELS TO SAMPLE_SUBMISSION.CSV\nfor i in range(len(idx_mnist)):\n    if dataset_from[i] == 'test':\n        sample_submission.loc[original_idx[i], 'Label'] = labels[idx_mnist[i]]\n\n# SAVING SUBMISSION.CSV\nsample_submission.to_csv('submission.csv', index=False)\nprint(\"submission.csv saved.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-11T08:02:47.346351Z","iopub.execute_input":"2025-06-11T08:02:47.346578Z","iopub.status.idle":"2025-06-11T08:02:48.952598Z","shell.execute_reply.started":"2025-06-11T08:02:47.346559Z","shell.execute_reply":"2025-06-11T08:02:48.951882Z"}},"outputs":[],"execution_count":null}]}