{"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\nfrom tensorflow import keras\nimport seaborn as sns\nimport pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-24T10:36:23.370058Z","iopub.execute_input":"2021-08-24T10:36:23.370379Z","iopub.status.idle":"2021-08-24T10:36:28.512252Z","shell.execute_reply.started":"2021-08-24T10:36:23.370350Z","shell.execute_reply":"2021-08-24T10:36:28.511389Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_csv = pd.read_csv('../input/digit-recognizer/train.csv')\ntest_csv = pd.read_csv('../input/digit-recognizer/test.csv')\n\ntrain_x = train_csv[[f'pixel{i}' for i in range(784)]]\ntrain_y = pd.get_dummies(train_csv['label'])\n\n\nX_train, X_test, y_train, y_test = train_test_split(train_x, train_y, test_size=0.33, random_state=42)\n\ntest_x = test_csv[[f'pixel{i}' for i in range(784)]]","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:39:40.785927Z","iopub.execute_input":"2021-08-24T10:39:40.786263Z","iopub.status.idle":"2021-08-24T10:39:44.923088Z","shell.execute_reply.started":"2021-08-24T10:39:40.786234Z","shell.execute_reply":"2021-08-24T10:39:44.922215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = keras.Sequential([\n    keras.layers.Dense(784, activation='relu'),\n    keras.layers.Dense(1024, activation='relu'),\n    keras.layers.Dense(10, activation='softmax')\n])","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:39:47.546379Z","iopub.execute_input":"2021-08-24T10:39:47.546723Z","iopub.status.idle":"2021-08-24T10:39:49.337239Z","shell.execute_reply.started":"2021-08-24T10:39:47.546672Z","shell.execute_reply":"2021-08-24T10:39:49.336330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam', loss='categorical_crossentropy', metrics='acc')","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:39:50.914107Z","iopub.execute_input":"2021-08-24T10:39:50.914436Z","iopub.status.idle":"2021-08-24T10:39:50.932678Z","shell.execute_reply.started":"2021-08-24T10:39:50.914405Z","shell.execute_reply":"2021-08-24T10:39:50.931587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:39:55.868362Z","iopub.execute_input":"2021-08-24T10:39:55.868722Z","iopub.status.idle":"2021-08-24T10:40:25.688721Z","shell.execute_reply.started":"2021-08-24T10:39:55.868671Z","shell.execute_reply":"2021-08-24T10:40:25.687959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss, acc = model.evaluate(X_test, y_test)\nprint(acc)","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:40:30.774615Z","iopub.execute_input":"2021-08-24T10:40:30.774989Z","iopub.status.idle":"2021-08-24T10:40:31.927966Z","shell.execute_reply.started":"2021-08-24T10:40:30.774956Z","shell.execute_reply":"2021-08-24T10:40:31.927171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_matrix = model.predict(test_x)\noutput_matrix.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:42:00.802268Z","iopub.execute_input":"2021-08-24T10:42:00.802590Z","iopub.status.idle":"2021-08-24T10:42:01.670410Z","shell.execute_reply.started":"2021-08-24T10:42:00.802559Z","shell.execute_reply":"2021-08-24T10:42:01.669612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_column = np.argmax(output_matrix, axis=1)\noutput_column","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:42:56.904911Z","iopub.execute_input":"2021-08-24T10:42:56.905229Z","iopub.status.idle":"2021-08-24T10:42:56.912483Z","shell.execute_reply.started":"2021-08-24T10:42:56.905199Z","shell.execute_reply":"2021-08-24T10:42:56.911408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_csv = pd.read_csv('../input/digit-recognizer/sample_submission.csv')\noutput_csv[\"Label\"] = output_column\noutput_csv.to_csv('output.csv', index=False)\n","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:53:16.635369Z","iopub.execute_input":"2021-08-24T10:53:16.635790Z","iopub.status.idle":"2021-08-24T10:53:16.698357Z","shell.execute_reply.started":"2021-08-24T10:53:16.635755Z","shell.execute_reply":"2021-08-24T10:53:16.697450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_csv.describe()","metadata":{"execution":{"iopub.status.busy":"2021-08-24T10:48:45.533989Z","iopub.execute_input":"2021-08-24T10:48:45.534338Z","iopub.status.idle":"2021-08-24T10:48:45.558180Z","shell.execute_reply.started":"2021-08-24T10:48:45.534296Z","shell.execute_reply":"2021-08-24T10:48:45.557350Z"},"trusted":true},"execution_count":null,"outputs":[]}]}