{"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":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30648,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-24T14:49:14.943245Z","iopub.execute_input":"2024-02-24T14:49:14.943870Z","iopub.status.idle":"2024-02-24T14:49:15.839239Z","shell.execute_reply.started":"2024-02-24T14:49:14.943836Z","shell.execute_reply":"2024-02-24T14:49:15.838133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!nvidia-smi","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:49:15.840794Z","iopub.execute_input":"2024-02-24T14:49:15.841169Z","iopub.status.idle":"2024-02-24T14:49:16.892238Z","shell.execute_reply.started":"2024-02-24T14:49:15.841144Z","shell.execute_reply":"2024-02-24T14:49:16.891031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:49:24.275139Z","iopub.execute_input":"2024-02-24T14:49:24.275522Z","iopub.status.idle":"2024-02-24T14:49:35.973936Z","shell.execute_reply.started":"2024-02-24T14:49:24.275490Z","shell.execute_reply":"2024-02-24T14:49:35.972908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ndata_test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:50:35.668950Z","iopub.execute_input":"2024-02-24T14:50:35.669321Z","iopub.status.idle":"2024-02-24T14:50:41.850356Z","shell.execute_reply.started":"2024-02-24T14:50:35.669294Z","shell.execute_reply":"2024-02-24T14:50:41.849581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_train.head()","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:50:45.171409Z","iopub.execute_input":"2024-02-24T14:50:45.172342Z","iopub.status.idle":"2024-02-24T14:50:45.196479Z","shell.execute_reply.started":"2024-02-24T14:50:45.172301Z","shell.execute_reply":"2024-02-24T14:50:45.195519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_test.head()","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:50:49.917546Z","iopub.execute_input":"2024-02-24T14:50:49.918392Z","iopub.status.idle":"2024-02-24T14:50:49.935413Z","shell.execute_reply.started":"2024-02-24T14:50:49.918362Z","shell.execute_reply":"2024-02-24T14:50:49.934118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = data_train.drop('label', axis=1)\ny_train = data_train['label']","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:52:27.846207Z","iopub.execute_input":"2024-02-24T14:52:27.847150Z","iopub.status.idle":"2024-02-24T14:52:27.930152Z","shell.execute_reply.started":"2024-02-24T14:52:27.847114Z","shell.execute_reply":"2024-02-24T14:52:27.929365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train / 255.0\nx_train = x_train.values.reshape(-1, 28, 28, 1)","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:53:03.189013Z","iopub.execute_input":"2024-02-24T14:53:03.189377Z","iopub.status.idle":"2024-02-24T14:53:03.246837Z","shell.execute_reply.started":"2024-02-24T14:53:03.189348Z","shell.execute_reply":"2024-02-24T14:53:03.246014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_test = data_test / 255.0\ndata_test = data_test.values.reshape(-1, 28, 28, 1)","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:55:33.283755Z","iopub.execute_input":"2024-02-24T14:55:33.284118Z","iopub.status.idle":"2024-02-24T14:55:33.324559Z","shell.execute_reply.started":"2024-02-24T14:55:33.284090Z","shell.execute_reply":"2024-02-24T14:55:33.323702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.models.Sequential([\n    tf.keras.layers.Conv2D(64, (3, 3), activation='relu', input_shape=(28, 28, 1)),\n    tf.keras.layers.MaxPooling2D(2, 2),\n    tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),\n    tf.keras.layers.MaxPooling2D(2, 2),\n    tf.keras.layers.Flatten(),\n    tf.keras.layers.Dense(256, activation='relu'),\n    tf.keras.layers.Dense(126, activation='relu'),\n    tf.keras.layers.Dense(10, activation='softmax')\n])","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:55:54.808085Z","iopub.execute_input":"2024-02-24T14:55:54.808741Z","iopub.status.idle":"2024-02-24T14:55:55.588397Z","shell.execute_reply.started":"2024-02-24T14:55:54.808708Z","shell.execute_reply":"2024-02-24T14:55:55.587464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer=tf.keras.optimizers.Adam(),\n                loss='sparse_categorical_crossentropy',\n                metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:56:01.053191Z","iopub.execute_input":"2024-02-24T14:56:01.054083Z","iopub.status.idle":"2024-02-24T14:56:01.073437Z","shell.execute_reply.started":"2024-02-24T14:56:01.054049Z","shell.execute_reply":"2024-02-24T14:56:01.072458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:56:06.372081Z","iopub.execute_input":"2024-02-24T14:56:06.372942Z","iopub.status.idle":"2024-02-24T14:56:06.404755Z","shell.execute_reply.started":"2024-02-24T14:56:06.372890Z","shell.execute_reply":"2024-02-24T14:56:06.403766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train, y_train, epochs=10)","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:56:27.191584Z","iopub.execute_input":"2024-02-24T14:56:27.192200Z","iopub.status.idle":"2024-02-24T14:57:16.119827Z","shell.execute_reply.started":"2024-02-24T14:56:27.192169Z","shell.execute_reply":"2024-02-24T14:57:16.118972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(data_test)\npredict = np.argmax(predictions, axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:57:32.172140Z","iopub.execute_input":"2024-02-24T14:57:32.172510Z","iopub.status.idle":"2024-02-24T14:57:34.479734Z","shell.execute_reply.started":"2024-02-24T14:57:32.172481Z","shell.execute_reply":"2024-02-24T14:57:34.478720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results= pd.Series(predict, name=\"Label\")\nsubmission= pd.concat([pd.Series(range(1,28001), name=\"ImageId\"), results], axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:57:34.883384Z","iopub.execute_input":"2024-02-24T14:57:34.884382Z","iopub.status.idle":"2024-02-24T14:57:34.891082Z","shell.execute_reply.started":"2024-02-24T14:57:34.884346Z","shell.execute_reply":"2024-02-24T14:57:34.890103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2024-02-24T14:58:27.908717Z","iopub.execute_input":"2024-02-24T14:58:27.909328Z","iopub.status.idle":"2024-02-24T14:58:27.957232Z","shell.execute_reply.started":"2024-02-24T14:58:27.909300Z","shell.execute_reply":"2024-02-24T14:58:27.956423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}