{"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":30627,"isInternetEnabled":false,"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":"121082ee-6a46-41f5-98f4-29246c4ce515","_cell_guid":"9016be7a-870d-4bd3-94e3-f4d835d36ed6","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2024-09-24T07:44:28.417329Z","iopub.execute_input":"2024-09-24T07:44:28.417723Z","iopub.status.idle":"2024-09-24T07:44:28.865900Z","shell.execute_reply.started":"2024-09-24T07:44:28.417690Z","shell.execute_reply":"2024-09-24T07:44:28.864768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"_uuid":"934e6849-a488-467f-8843-526e0eb81a35","_cell_guid":"aa1b90d9-6631-4d9b-9f50-3ded1e8de83e","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2024-09-24T07:44:33.493226Z","iopub.execute_input":"2024-09-24T07:44:33.493914Z","iopub.status.idle":"2024-09-24T07:44:40.573618Z","shell.execute_reply.started":"2024-09-24T07:44:33.493867Z","shell.execute_reply":"2024-09-24T07:44:40.572661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import keras\n\ny_train = keras.utils.to_categorical(data[\"label\"])\nx_train = data.drop(\"label\", axis=1) / 255","metadata":{"_uuid":"d4f327b6-6bd6-4fb4-9c3f-45a147f2de9a","_cell_guid":"3c3eb932-4750-4903-9cbe-7603f0976dee","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2024-09-24T07:44:45.922111Z","iopub.execute_input":"2024-09-24T07:44:45.922536Z","iopub.status.idle":"2024-09-24T07:44:59.447397Z","shell.execute_reply.started":"2024-09-24T07:44:45.922500Z","shell.execute_reply":"2024-09-24T07:44:59.446300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nmodel = keras.Sequential([\n    keras.layers.Input(shape=(784,)),\n#     keras.layers.Dropout(0.2),\n    keras.layers.Dense(64, activation='relu'),\n    keras.layers.Dropout(0.2),\n    keras.layers.Dense(10, activation='softmax')\n])\n\nmodel.compile(loss=\"categorical_crossentropy\", optimizer=\"adam\", metrics=[\"accuracy\"])\ntraining = model.fit(x_train, y_train, batch_size=32, epochs=10, validation_split=0.1)\n\nplt.plot(training.history['accuracy'])\nplt.plot(training.history['val_accuracy'])\nplt.title('model accuracy')\nplt.ylabel('accuracy')\nplt.xlabel('epoch')\nplt.legend(['train', 'validation'], loc='upper left')\nplt.show()","metadata":{"_uuid":"ac427d51-c04d-499c-bc79-45f6e39976c5","_cell_guid":"c29ca4b5-8da5-487e-b652-696f2b287df4","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2024-09-24T07:45:11.480279Z","iopub.execute_input":"2024-09-24T07:45:11.481243Z","iopub.status.idle":"2024-09-24T07:45:43.706785Z","shell.execute_reply.started":"2024-09-24T07:45:11.481196Z","shell.execute_reply":"2024-09-24T07:45:43.705693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(test)\nsub = pd.read_csv(\"/kaggle/input/digit-recognizer/sample_submission.csv\")\nsub[\"Label\"] = np.argmax(y_pred, axis=1)\n# sub.to_csv(\"neural_network.csv\", index=False)\nprint(sub)","metadata":{"_uuid":"177492f8-342e-4130-87a5-f58037e076d7","_cell_guid":"dc14659a-c08c-4d57-b00b-1d1f44644e7b","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2024-09-24T07:47:17.799095Z","iopub.execute_input":"2024-09-24T07:47:17.799734Z","iopub.status.idle":"2024-09-24T07:47:20.647094Z","shell.execute_reply.started":"2024-09-24T07:47:17.799686Z","shell.execute_reply":"2024-09-24T07:47:20.644876Z"},"trusted":true},"execution_count":null,"outputs":[]}]}