{"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 numpy as np\nimport pandas as pd\nfrom matplotlib import pyplot as plt\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense\nfrom sklearn.model_selection import KFold","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:14:37.405114Z","iopub.execute_input":"2023-01-16T12:14:37.405910Z","iopub.status.idle":"2023-01-16T12:14:37.745225Z","shell.execute_reply.started":"2023-01-16T12:14:37.405857Z","shell.execute_reply":"2023-01-16T12:14:37.743982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\ntrain = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\nsubmission = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:20:28.591774Z","iopub.execute_input":"2023-01-16T12:20:28.592727Z","iopub.status.idle":"2023-01-16T12:20:33.454526Z","shell.execute_reply.started":"2023-01-16T12:20:28.592602Z","shell.execute_reply":"2023-01-16T12:20:33.453544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('train: {}'.format(train.shape))\nprint('test: {}'.format(test.shape))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T11:31:38.568532Z","iopub.execute_input":"2023-01-16T11:31:38.568951Z","iopub.status.idle":"2023-01-16T11:31:38.574958Z","shell.execute_reply.started":"2023-01-16T11:31:38.568918Z","shell.execute_reply":"2023-01-16T11:31:38.573798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['label']","metadata":{"execution":{"iopub.status.busy":"2023-01-16T11:36:31.105750Z","iopub.execute_input":"2023-01-16T11:36:31.106157Z","iopub.status.idle":"2023-01-16T11:36:31.114463Z","shell.execute_reply.started":"2023-01-16T11:36:31.106125Z","shell.execute_reply":"2023-01-16T11:36:31.113691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train.drop(columns=['label'])\ny_train = train['label']","metadata":{"execution":{"iopub.status.busy":"2023-01-16T11:38:30.427195Z","iopub.execute_input":"2023-01-16T11:38:30.428176Z","iopub.status.idle":"2023-01-16T11:38:30.555167Z","shell.execute_reply.started":"2023-01-16T11:38:30.428138Z","shell.execute_reply":"2023-01-16T11:38:30.554032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('X_train: {}'.format(X_train.shape))\nprint('y_train: {}'.format(y_train.shape))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T11:38:56.246607Z","iopub.execute_input":"2023-01-16T11:38:56.247039Z","iopub.status.idle":"2023-01-16T11:38:56.253253Z","shell.execute_reply.started":"2023-01-16T11:38:56.247004Z","shell.execute_reply":"2023-01-16T11:38:56.252153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train = to_categorical(y_train, 10)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:07:49.965837Z","iopub.execute_input":"2023-01-16T12:07:49.967076Z","iopub.status.idle":"2023-01-16T12:07:49.976173Z","shell.execute_reply.started":"2023-01-16T12:07:49.967024Z","shell.execute_reply":"2023-01-16T12:07:49.975158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:08:00.497425Z","iopub.execute_input":"2023-01-16T12:08:00.497825Z","iopub.status.idle":"2023-01-16T12:08:00.504740Z","shell.execute_reply.started":"2023-01-16T12:08:00.497791Z","shell.execute_reply":"2023-01-16T12:08:00.503655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(Dense(800, activation='relu',input_dim=X_train.shape[1]))\nmodel.add(Dense(800, activation='relu'))\nmodel.add(Dense(10 , activation='softmax',))\nmodel.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])\n\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:16:52.806750Z","iopub.execute_input":"2023-01-16T12:16:52.807193Z","iopub.status.idle":"2023-01-16T12:16:52.862405Z","shell.execute_reply.started":"2023-01-16T12:16:52.807156Z","shell.execute_reply":"2023-01-16T12:16:52.861266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x=X_train , y=y_train , epochs=10)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:17:04.854996Z","iopub.execute_input":"2023-01-16T12:17:04.855394Z","iopub.status.idle":"2023-01-16T12:18:39.794554Z","shell.execute_reply.started":"2023-01-16T12:17:04.855360Z","shell.execute_reply":"2023-01-16T12:18:39.793165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(test)\nclasses = pred.argmax(axis=-1)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:19:22.345023Z","iopub.execute_input":"2023-01-16T12:19:22.345396Z","iopub.status.idle":"2023-01-16T12:19:24.633351Z","shell.execute_reply.started":"2023-01-16T12:19:22.345365Z","shell.execute_reply":"2023-01-16T12:19:24.632334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:19:33.741620Z","iopub.execute_input":"2023-01-16T12:19:33.742050Z","iopub.status.idle":"2023-01-16T12:19:33.751586Z","shell.execute_reply.started":"2023-01-16T12:19:33.742008Z","shell.execute_reply":"2023-01-16T12:19:33.750355Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.Label = classes\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:20:57.238164Z","iopub.execute_input":"2023-01-16T12:20:57.238566Z","iopub.status.idle":"2023-01-16T12:20:57.251103Z","shell.execute_reply.started":"2023-01-16T12:20:57.238533Z","shell.execute_reply":"2023-01-16T12:20:57.249788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"sub_1.csv\", index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T12:21:06.385552Z","iopub.execute_input":"2023-01-16T12:21:06.386669Z","iopub.status.idle":"2023-01-16T12:21:06.422035Z","shell.execute_reply.started":"2023-01-16T12:21:06.386605Z","shell.execute_reply":"2023-01-16T12:21:06.420875Z"},"trusted":true},"execution_count":null,"outputs":[]}]}