{"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.13"},"papermill":{"default_parameters":{},"duration":753.081688,"end_time":"2024-04-06T10:14:21.396969","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-04-06T10:01:48.315281","version":"2.5.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport warnings\nwarnings.filterwarnings(\"ignore\")\nimport os\npd.plotting.register_matplotlib_converters()\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport seaborn as sns\nsns.set_style(\"dark\") \nsns.set_palette(\"copper\")\nfrom xgboost import XGBClassifier\nfrom xgboost.callback import EarlyStopping\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nscaler= StandardScaler()","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":3.615111,"end_time":"2024-04-06T10:01:55.354529","exception":false,"start_time":"2024-04-06T10:01:51.739418","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:53.659314Z","iopub.execute_input":"2024-04-07T17:26:53.659806Z","iopub.status.idle":"2024-04-07T17:26:53.673864Z","shell.execute_reply.started":"2024-04-07T17:26:53.659770Z","shell.execute_reply":"2024-04-07T17:26:53.672651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data=pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntesting_data=pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"papermill":{"duration":8.06066,"end_time":"2024-04-06T10:02:03.421861","exception":false,"start_time":"2024-04-06T10:01:55.361201","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:53.676123Z","iopub.execute_input":"2024-04-07T17:26:53.677366Z","iopub.status.idle":"2024-04-07T17:26:59.349503Z","shell.execute_reply.started":"2024-04-07T17:26:53.677332Z","shell.execute_reply":"2024-04-07T17:26:59.348345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data.head(10)","metadata":{"papermill":{"duration":0.039737,"end_time":"2024-04-06T10:02:03.467895","exception":false,"start_time":"2024-04-06T10:02:03.428158","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:59.351146Z","iopub.execute_input":"2024-04-07T17:26:59.351580Z","iopub.status.idle":"2024-04-07T17:26:59.385781Z","shell.execute_reply.started":"2024-04-07T17:26:59.351524Z","shell.execute_reply":"2024-04-07T17:26:59.384406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testing_data.head(10)","metadata":{"papermill":{"duration":0.034505,"end_time":"2024-04-06T10:02:03.509295","exception":false,"start_time":"2024-04-06T10:02:03.474790","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:59.390172Z","iopub.execute_input":"2024-04-07T17:26:59.390616Z","iopub.status.idle":"2024-04-07T17:26:59.415167Z","shell.execute_reply.started":"2024-04-07T17:26:59.390553Z","shell.execute_reply":"2024-04-07T17:26:59.413351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data.info()","metadata":{"papermill":{"duration":0.070615,"end_time":"2024-04-06T10:02:03.587509","exception":false,"start_time":"2024-04-06T10:02:03.516894","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:59.417265Z","iopub.execute_input":"2024-04-07T17:26:59.417749Z","iopub.status.idle":"2024-04-07T17:26:59.635175Z","shell.execute_reply.started":"2024-04-07T17:26:59.417713Z","shell.execute_reply":"2024-04-07T17:26:59.633962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testing_data.info()","metadata":{"papermill":{"duration":0.054946,"end_time":"2024-04-06T10:02:03.650348","exception":false,"start_time":"2024-04-06T10:02:03.595402","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:59.636830Z","iopub.execute_input":"2024-04-07T17:26:59.637660Z","iopub.status.idle":"2024-04-07T17:26:59.684138Z","shell.execute_reply.started":"2024-04-07T17:26:59.637616Z","shell.execute_reply":"2024-04-07T17:26:59.683252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data.describe()","metadata":{"papermill":{"duration":2.312719,"end_time":"2024-04-06T10:02:05.970987","exception":false,"start_time":"2024-04-06T10:02:03.658268","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:26:59.685660Z","iopub.execute_input":"2024-04-07T17:26:59.686253Z","iopub.status.idle":"2024-04-07T17:27:01.896218Z","shell.execute_reply.started":"2024-04-07T17:26:59.686220Z","shell.execute_reply":"2024-04-07T17:27:01.894863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testing_data.describe()","metadata":{"papermill":{"duration":1.919547,"end_time":"2024-04-06T10:02:07.899335","exception":false,"start_time":"2024-04-06T10:02:05.979788","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:01.897578Z","iopub.execute_input":"2024-04-07T17:27:01.897916Z","iopub.status.idle":"2024-04-07T17:27:03.867765Z","shell.execute_reply.started":"2024-04-07T17:27:01.897888Z","shell.execute_reply":"2024-04-07T17:27:03.866381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data.isnull().sum()","metadata":{"papermill":{"duration":0.052064,"end_time":"2024-04-06T10:02:07.960268","exception":false,"start_time":"2024-04-06T10:02:07.908204","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:03.869246Z","iopub.execute_input":"2024-04-07T17:27:03.869583Z","iopub.status.idle":"2024-04-07T17:27:03.908721Z","shell.execute_reply.started":"2024-04-07T17:27:03.869538Z","shell.execute_reply":"2024-04-07T17:27:03.907426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"testing_data.isnull().sum()","metadata":{"papermill":{"duration":0.040811,"end_time":"2024-04-06T10:02:08.009805","exception":false,"start_time":"2024-04-06T10:02:07.968994","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:03.912361Z","iopub.execute_input":"2024-04-07T17:27:03.912726Z","iopub.status.idle":"2024-04-07T17:27:03.939783Z","shell.execute_reply.started":"2024-04-07T17:27:03.912698Z","shell.execute_reply":"2024-04-07T17:27:03.938182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data.duplicated().sum()","metadata":{"papermill":{"duration":0.507526,"end_time":"2024-04-06T10:02:08.526475","exception":false,"start_time":"2024-04-06T10:02:08.018949","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:03.941107Z","iopub.execute_input":"2024-04-07T17:27:03.941432Z","iopub.status.idle":"2024-04-07T17:27:04.431413Z","shell.execute_reply.started":"2024-04-07T17:27:03.941405Z","shell.execute_reply":"2024-04-07T17:27:04.430291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_training_data = training_data.drop(['label'], axis=1)\nY_training_data = training_data['label']\nX_training_data = pd.DataFrame(scaler.fit_transform(X_training_data), columns=X_training_data.columns)\ntesting_data = pd.DataFrame(scaler.fit_transform(testing_data), columns=testing_data.columns)","metadata":{"papermill":{"duration":0.992108,"end_time":"2024-04-06T10:02:09.528598","exception":false,"start_time":"2024-04-06T10:02:08.536490","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:04.432920Z","iopub.execute_input":"2024-04-07T17:27:04.433387Z","iopub.status.idle":"2024-04-07T17:27:05.491204Z","shell.execute_reply.started":"2024-04-07T17:27:04.433358Z","shell.execute_reply":"2024-04-07T17:27:05.489945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_training_data=(X_training_data).values\nY_training_data=(Y_training_data).values\nX_training_data = X_training_data.reshape(42000, 28, 28, 1)\nX_testing_data=testing_data.values\nX_testing_data = X_testing_data.reshape(28000, 28, 28, 1)","metadata":{"papermill":{"duration":0.018967,"end_time":"2024-04-06T10:02:09.556838","exception":false,"start_time":"2024-04-06T10:02:09.537871","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:05.493334Z","iopub.execute_input":"2024-04-07T17:27:05.494216Z","iopub.status.idle":"2024-04-07T17:27:05.501410Z","shell.execute_reply.started":"2024-04-07T17:27:05.494172Z","shell.execute_reply":"2024-04-07T17:27:05.500162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers, models\nmodel = models.Sequential([\n    layers.Conv2D(filters=32, kernel_size=(2, 2), activation='relu', input_shape=(28, 28, 1)),\n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(filters=64, kernel_size=(2, 2), activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n    layers.Conv2D(filters=128, kernel_size=(2, 2), activation='relu'),\n    layers.MaxPooling2D((2, 2)),\n\n    \n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dropout(0.2),\n    layers.Dense(72, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(48, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(24, activation='relu'),\n    layers.Dropout(0.2),\n    layers.Dense(10, activation='softmax')\n])\nmodel.compile(optimizer='adam',\n             loss='sparse_categorical_crossentropy',\n             metrics=['accuracy'])\nmodel.fit(X_training_data, Y_training_data, epochs=25, validation_split=0.2)","metadata":{"papermill":{"duration":716.58643,"end_time":"2024-04-06T10:14:06.152452","exception":false,"start_time":"2024-04-06T10:02:09.566022","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-04-07T17:27:05.503381Z","iopub.execute_input":"2024-04-07T17:27:05.503836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=model.predict(X_testing_data)\npred_classes=[np.argmax(element) for element in pred]\ntesting_data['label']=pred_classes\ntesting_data['ImageId'] = (testing_data.reset_index().index)+1\nSubmission=testing_data[['ImageId', 'label']]\nSubmission.to_csv('submission.csv', index=None)","metadata":{"papermill":{"duration":7.282472,"end_time":"2024-04-06T10:14:14.365383","exception":false,"start_time":"2024-04-06T10:14:07.082911","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Submission","metadata":{"papermill":{"duration":0.946805,"end_time":"2024-04-06T10:14:16.180660","exception":false,"start_time":"2024-04-06T10:14:15.233855","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]}]}