{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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"}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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":"2023-12-29T20:51:19.153536Z","iopub.execute_input":"2023-12-29T20:51:19.154000Z","iopub.status.idle":"2023-12-29T20:51:19.166258Z","shell.execute_reply.started":"2023-12-29T20:51:19.153962Z","shell.execute_reply":"2023-12-29T20:51:19.164730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.utils import to_categorical\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:19.168596Z","iopub.execute_input":"2023-12-29T20:51:19.169031Z","iopub.status.idle":"2023-12-29T20:51:19.175049Z","shell.execute_reply.started":"2023-12-29T20:51:19.168997Z","shell.execute_reply":"2023-12-29T20:51:19.173685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")\n\ntrain.info()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:19.176605Z","iopub.execute_input":"2023-12-29T20:51:19.177041Z","iopub.status.idle":"2023-12-29T20:51:24.414789Z","shell.execute_reply.started":"2023-12-29T20:51:19.177004Z","shell.execute_reply":"2023-12-29T20:51:24.413593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_train = train[\"label\"]\n\nX_train = train.drop(\"label\",axis = 1) ","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.417684Z","iopub.execute_input":"2023-12-29T20:51:24.418047Z","iopub.status.idle":"2023-12-29T20:51:24.506512Z","shell.execute_reply.started":"2023-12-29T20:51:24.418016Z","shell.execute_reply":"2023-12-29T20:51:24.505120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_train.value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.508094Z","iopub.execute_input":"2023-12-29T20:51:24.508568Z","iopub.status.idle":"2023-12-29T20:51:24.521450Z","shell.execute_reply.started":"2023-12-29T20:51:24.508536Z","shell.execute_reply":"2023-12-29T20:51:24.520272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.isnull().any().values.sum()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.522923Z","iopub.execute_input":"2023-12-29T20:51:24.523231Z","iopub.status.idle":"2023-12-29T20:51:24.542917Z","shell.execute_reply.started":"2023-12-29T20:51:24.523205Z","shell.execute_reply":"2023-12-29T20:51:24.541790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isnull().any().values.sum()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.544331Z","iopub.execute_input":"2023-12-29T20:51:24.544882Z","iopub.status.idle":"2023-12-29T20:51:24.558027Z","shell.execute_reply.started":"2023-12-29T20:51:24.544851Z","shell.execute_reply":"2023-12-29T20:51:24.556869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train / 255.0\ntest = test / 255.0","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.559431Z","iopub.execute_input":"2023-12-29T20:51:24.559774Z","iopub.status.idle":"2023-12-29T20:51:24.664147Z","shell.execute_reply.started":"2023-12-29T20:51:24.559745Z","shell.execute_reply":"2023-12-29T20:51:24.663278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.to_numpy().reshape(-1,28,28,1)\ntest = test.to_numpy().reshape(-1,28,28,1)\nprint(\"test shape: \", test.shape)\nprint(\"X_train shape: \", X_train.shape)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.667227Z","iopub.execute_input":"2023-12-29T20:51:24.667804Z","iopub.status.idle":"2023-12-29T20:51:24.673886Z","shell.execute_reply.started":"2023-12-29T20:51:24.667770Z","shell.execute_reply":"2023-12-29T20:51:24.673096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_train = to_categorical(Y_train, num_classes = 10)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.675271Z","iopub.execute_input":"2023-12-29T20:51:24.675796Z","iopub.status.idle":"2023-12-29T20:51:24.683176Z","shell.execute_reply.started":"2023-12-29T20:51:24.675765Z","shell.execute_reply":"2023-12-29T20:51:24.682377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.title(Y_train[144])\nplt.plot(Y_train[144])\nplt.xticks(range(10));","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:24.684460Z","iopub.execute_input":"2023-12-29T20:51:24.684952Z","iopub.status.idle":"2023-12-29T20:51:25.026352Z","shell.execute_reply.started":"2023-12-29T20:51:24.684922Z","shell.execute_reply":"2023-12-29T20:51:25.025293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.1, random_state=42)\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":"2023-12-29T20:51:25.027664Z","iopub.execute_input":"2023-12-29T20:51:25.027988Z","iopub.status.idle":"2023-12-29T20:51:25.452345Z","shell.execute_reply.started":"2023-12-29T20:51:25.027959Z","shell.execute_reply":"2023-12-29T20:51:25.451450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(X_train[2][:,:,0],cmap='gray')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T20:51:25.453470Z","iopub.execute_input":"2023-12-29T20:51:25.454493Z","iopub.status.idle":"2023-12-29T20:51:25.706292Z","shell.execute_reply.started":"2023-12-29T20:51:25.454459Z","shell.execute_reply":"2023-12-29T20:51:25.705165Z"},"trusted":true},"execution_count":null,"outputs":[]}]}