{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)import numpy as np # linear algebra\nimport numpy as np\n","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.status.busy":"2022-03-10T14:32:51.381534Z","iopub.execute_input":"2022-03-10T14:32:51.381858Z","iopub.status.idle":"2022-03-10T14:32:51.386339Z","shell.execute_reply.started":"2022-03-10T14:32:51.381827Z","shell.execute_reply":"2022-03-10T14:32:51.385514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df=pd.read_csv(\"../input/digit-recognizer/train.csv\")\ntest_df=pd.read_csv(\"../input/digit-recognizer/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:51.388133Z","iopub.execute_input":"2022-03-10T14:32:51.388541Z","iopub.status.idle":"2022-03-10T14:32:56.095265Z","shell.execute_reply.started":"2022-03-10T14:32:51.388509Z","shell.execute_reply":"2022-03-10T14:32:56.094317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train=train_df.pop('label')\nI_train=np.array(train_df)\nI_test=np.array(test_df)","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.096544Z","iopub.execute_input":"2022-03-10T14:32:56.096894Z","iopub.status.idle":"2022-03-10T14:32:56.457060Z","shell.execute_reply.started":"2022-03-10T14:32:56.096851Z","shell.execute_reply":"2022-03-10T14:32:56.456184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train=I_train.reshape(-1,28,28,1)\nX_test=I_test.reshape(-1,28,28,1)","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.462723Z","iopub.execute_input":"2022-03-10T14:32:56.463601Z","iopub.status.idle":"2022-03-10T14:32:56.470912Z","shell.execute_reply.started":"2022-03-10T14:32:56.463546Z","shell.execute_reply":"2022-03-10T14:32:56.469588Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.max())\nX_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.472606Z","iopub.execute_input":"2022-03-10T14:32:56.472902Z","iopub.status.idle":"2022-03-10T14:32:56.529841Z","shell.execute_reply.started":"2022-03-10T14:32:56.472872Z","shell.execute_reply":"2022-03-10T14:32:56.528806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.astype('float32')/255\nX_test = X_test.astype('float32')/255","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.531607Z","iopub.execute_input":"2022-03-10T14:32:56.531955Z","iopub.status.idle":"2022-03-10T14:32:56.664801Z","shell.execute_reply.started":"2022-03-10T14:32:56.531913Z","shell.execute_reply":"2022-03-10T14:32:56.663678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import keras\nfrom keras.models import Model\nfrom keras.layers import Dense, Input,Dropout\nfrom keras.layers import Conv2D,MaxPooling2D,Activation,Flatten,BatchNormalization\nfrom keras.utils import np_utils\nfrom tensorflow.keras.models import Sequential, Model","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.666086Z","iopub.execute_input":"2022-03-10T14:32:56.666352Z","iopub.status.idle":"2022-03-10T14:32:56.671790Z","shell.execute_reply.started":"2022-03-10T14:32:56.666323Z","shell.execute_reply":"2022-03-10T14:32:56.671058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape)\nprint(y_train.shape)","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.673195Z","iopub.execute_input":"2022-03-10T14:32:56.673980Z","iopub.status.idle":"2022-03-10T14:32:56.686281Z","shell.execute_reply.started":"2022-03-10T14:32:56.673931Z","shell.execute_reply":"2022-03-10T14:32:56.685597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Flatten(input_shape=(28,28,1)))\nmodel.add(Dense(512,activation='relu'))\nmodel.add(Dense(256,activation='relu'))\nmodel.add(Dense(128,activation='relu'))\nmodel.add(Dense(64,activation='relu'))\nmodel.add(Dense(32,activation='relu'))\nmodel.add(Dense(16,activation='relu'))\nmodel.add(Dense(10,activation='softmax'))\nmodel.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\nmodel.fit(x=X_train,y=y_train,batch_size=60,epochs=100)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:32:56.688553Z","iopub.execute_input":"2022-03-10T14:32:56.689176Z","iopub.status.idle":"2022-03-10T14:34:45.936724Z","shell.execute_reply.started":"2022-03-10T14:32:56.689103Z","shell.execute_reply":"2022-03-10T14:34:45.935803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_test)\ny_pred = y_pred.argmax(axis=-1)\ny_pred","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:34:45.938022Z","iopub.execute_input":"2022-03-10T14:34:45.938483Z","iopub.status.idle":"2022-03-10T14:34:47.908786Z","shell.execute_reply.started":"2022-03-10T14:34:45.938453Z","shell.execute_reply":"2022-03-10T14:34:47.907703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#SUBMITTING PREDICTIONS\nsub=pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv', header='infer')\nsub[\"Label\"]=y_pred\nsub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-10T14:34:47.910237Z","iopub.execute_input":"2022-03-10T14:34:47.910554Z","iopub.status.idle":"2022-03-10T14:34:47.973568Z","shell.execute_reply.started":"2022-03-10T14:34:47.910511Z","shell.execute_reply":"2022-03-10T14:34:47.972708Z"},"trusted":true},"execution_count":null,"outputs":[]}]}