{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","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":30673,"isInternetEnabled":true,"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":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-02T23:47:41.581610Z","iopub.execute_input":"2024-04-02T23:47:41.581963Z","iopub.status.idle":"2024-04-02T23:47:42.564568Z","shell.execute_reply.started":"2024-04-02T23:47:41.581937Z","shell.execute_reply":"2024-04-02T23:47:42.563376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This notebook is accompanied by a Medium article: \n# https://python.plainenglish.io/starting-with-tensorflow-on-kaggle-0785fb83c86d\nimport tensorflow as tf\nimport keras\nfrom keras.models import Sequential\nfrom keras.layers import Dense\n\nnum_neurons = 512\nnum_classes = 10\nepochs = 10","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:02.829428Z","iopub.execute_input":"2024-04-02T23:48:02.829796Z","iopub.status.idle":"2024-04-02T23:48:14.711097Z","shell.execute_reply.started":"2024-04-02T23:48:02.829769Z","shell.execute_reply":"2024-04-02T23:48:14.710248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\nx_test = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:19.555662Z","iopub.execute_input":"2024-04-02T23:48:19.556332Z","iopub.status.idle":"2024-04-02T23:48:24.714154Z","shell.execute_reply.started":"2024-04-02T23:48:19.556297Z","shell.execute_reply":"2024-04-02T23:48:24.713076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_data.shape)","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:30.588258Z","iopub.execute_input":"2024-04-02T23:48:30.588625Z","iopub.status.idle":"2024-04-02T23:48:30.593337Z","shell.execute_reply.started":"2024-04-02T23:48:30.588597Z","shell.execute_reply":"2024-04-02T23:48:30.592312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train=train_data.drop('label',axis=1)\ny_train=train_data.label.values","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:33.163601Z","iopub.execute_input":"2024-04-02T23:48:33.163967Z","iopub.status.idle":"2024-04-02T23:48:33.278151Z","shell.execute_reply.started":"2024-04-02T23:48:33.163940Z","shell.execute_reply":"2024-04-02T23:48:33.277314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(x_train.shape)","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:38.480906Z","iopub.execute_input":"2024-04-02T23:48:38.481294Z","iopub.status.idle":"2024-04-02T23:48:38.486287Z","shell.execute_reply.started":"2024-04-02T23:48:38.481258Z","shell.execute_reply":"2024-04-02T23:48:38.485131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train / 255.0\nx_test = x_test / 255.0","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:41.524073Z","iopub.execute_input":"2024-04-02T23:48:41.524819Z","iopub.status.idle":"2024-04-02T23:48:41.631035Z","shell.execute_reply.started":"2024-04-02T23:48:41.524781Z","shell.execute_reply":"2024-04-02T23:48:41.630231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([Dense(num_neurons, activation=tf.nn.relu), \n                    Dense(num_classes, activation=tf.nn.softmax)])\nmodel.compile(optimizer = 'adam',\n              loss = 'sparse_categorical_crossentropy',\n              metrics=['accuracy'])\n\nmodel.fit(x_train, y_train, epochs=epochs)","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:48:44.648063Z","iopub.execute_input":"2024-04-02T23:48:44.648466Z","iopub.status.idle":"2024-04-02T23:49:42.189634Z","shell.execute_reply.started":"2024-04-02T23:48:44.648437Z","shell.execute_reply":"2024-04-02T23:49:42.188514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test=model.predict(x_test)\ny_test=np.argmax(y_test,axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:50:03.981777Z","iopub.execute_input":"2024-04-02T23:50:03.982697Z","iopub.status.idle":"2024-04-02T23:50:05.905391Z","shell.execute_reply.started":"2024-04-02T23:50:03.982662Z","shell.execute_reply":"2024-04-02T23:50:05.904239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submit=pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\nsubmit.Label=y_test\nsubmit.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-04-02T23:50:16.444192Z","iopub.execute_input":"2024-04-02T23:50:16.445143Z","iopub.status.idle":"2024-04-02T23:50:16.493551Z","shell.execute_reply.started":"2024-04-02T23:50:16.445076Z","shell.execute_reply":"2024-04-02T23:50:16.492481Z"},"trusted":true},"execution_count":null,"outputs":[]}]}