{"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 tensorflow as tf","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-04T22:15:20.274365Z","iopub.execute_input":"2022-07-04T22:15:20.274635Z","iopub.status.idle":"2022-07-04T22:15:20.280065Z","shell.execute_reply.started":"2022-07-04T22:15:20.274600Z","shell.execute_reply":"2022-07-04T22:15:20.277635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\ndata = pd.read_csv('../input/digit-recognizer/train.csv')\n\nx_train = data.drop(['label'], axis ='columns')\ny_train = data['label']\nx_train = np.array(x_train)\nx_train = x_train.reshape(42000,28,28,1)/255","metadata":{"execution":{"iopub.status.busy":"2022-07-04T22:15:37.458803Z","iopub.execute_input":"2022-07-04T22:15:37.459107Z","iopub.status.idle":"2022-07-04T22:15:40.117804Z","shell.execute_reply.started":"2022-07-04T22:15:37.459074Z","shell.execute_reply":"2022-07-04T22:15:40.117080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = tf.keras.Sequential([tf.keras.layers.Conv2D(64,(3,3),activation='relu',input_shape=(28,28,1)),\n                                 tf.keras.layers.MaxPool2D(2,2),\n                                 tf.keras.layers.Dropout(0.15),\n                                 tf.keras.layers.Flatten(),\n                                 tf.keras.layers.Dense(128,activation='tanh'),\n                                 tf.keras.layers.Dense(10,activation='softmax')])\n\nmodel.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])\nmodel.fit(x_train,y_train,epochs=20)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T22:15:44.357863Z","iopub.execute_input":"2022-07-04T22:15:44.358408Z","iopub.status.idle":"2022-07-04T22:16:47.281922Z","shell.execute_reply.started":"2022-07-04T22:15:44.358374Z","shell.execute_reply":"2022-07-04T22:16:47.281207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('../input/digit-recognizer/test.csv')\ntest = np.array(test)\ntest = test.reshape(28000,28,28,1)/255\ntest.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-04T22:16:54.568668Z","iopub.execute_input":"2022-07-04T22:16:54.568946Z","iopub.status.idle":"2022-07-04T22:16:56.410736Z","shell.execute_reply.started":"2022-07-04T22:16:54.568917Z","shell.execute_reply":"2022-07-04T22:16:56.410008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = model.predict(test)\nresult","metadata":{"execution":{"iopub.status.busy":"2022-07-04T22:16:58.147103Z","iopub.execute_input":"2022-07-04T22:16:58.147779Z","iopub.status.idle":"2022-07-04T22:16:59.098479Z","shell.execute_reply.started":"2022-07-04T22:16:58.147732Z","shell.execute_reply":"2022-07-04T22:16:59.097708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final = np.empty(shape=(len(result)),dtype=np.int32)\nfor i in range(len(result)) :\n    col = result[i]\n    col = col.reshape(10,1)\n    final[i] = col.argmax()\n    \nfinal","metadata":{"execution":{"iopub.status.busy":"2022-07-04T22:17:01.708509Z","iopub.execute_input":"2022-07-04T22:17:01.709439Z","iopub.status.idle":"2022-07-04T22:17:01.781428Z","shell.execute_reply.started":"2022-07-04T22:17:01.709395Z","shell.execute_reply":"2022-07-04T22:17:01.780618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"index = np.arange(1,28001)\nprediction = np.c_[index,final]\n\nprediction = pd.DataFrame(prediction,columns={'Label','ImageId'})\nprediction.to_csv('prediction.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-04T22:19:04.578545Z","iopub.execute_input":"2022-07-04T22:19:04.578803Z","iopub.status.idle":"2022-07-04T22:19:04.649467Z","shell.execute_reply.started":"2022-07-04T22:19:04.578775Z","shell.execute_reply":"2022-07-04T22:19:04.648682Z"},"trusted":true},"execution_count":null,"outputs":[]}]}