{"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":"# 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":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2023-11-11T16:13:51.808213Z","iopub.status.busy":"2023-11-11T16:13:51.807794Z","iopub.status.idle":"2023-11-11T16:13:52.259234Z","shell.execute_reply":"2023-11-11T16:13:52.258043Z","shell.execute_reply.started":"2023-11-11T16:13:51.808178Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:16:08.527901Z","iopub.status.busy":"2023-11-11T16:16:08.527370Z","iopub.status.idle":"2023-11-11T16:16:13.031394Z","shell.execute_reply":"2023-11-11T16:16:13.030194Z","shell.execute_reply.started":"2023-11-11T16:16:08.527857Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:16:33.822872Z","iopub.status.busy":"2023-11-11T16:16:33.822454Z","iopub.status.idle":"2023-11-11T16:16:33.831006Z","shell.execute_reply":"2023-11-11T16:16:33.829501Z","shell.execute_reply.started":"2023-11-11T16:16:33.822841Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow\nfrom tensorflow import keras\nfrom tensorflow.keras import Sequential\nfrom tensorflow.keras.layers import Dense,Flatten","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:23:41.107319Z","iopub.status.busy":"2023-11-11T16:23:41.106886Z","iopub.status.idle":"2023-11-11T16:23:57.059036Z","shell.execute_reply":"2023-11-11T16:23:57.057318Z","shell.execute_reply.started":"2023-11-11T16:23:41.107287Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.iloc[0]","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:28:38.891657Z","iopub.status.busy":"2023-11-11T16:28:38.891231Z","iopub.status.idle":"2023-11-11T16:28:38.901820Z","shell.execute_reply":"2023-11-11T16:28:38.900489Z","shell.execute_reply.started":"2023-11-11T16:28:38.891609Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:30:29.206851Z","iopub.status.busy":"2023-11-11T16:30:29.206389Z","iopub.status.idle":"2023-11-11T16:30:31.800001Z","shell.execute_reply":"2023-11-11T16:30:31.798834Z","shell.execute_reply.started":"2023-11-11T16:30:29.206819Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:30:35.586664Z","iopub.status.busy":"2023-11-11T16:30:35.585154Z","iopub.status.idle":"2023-11-11T16:30:35.613614Z","shell.execute_reply":"2023-11-11T16:30:35.612483Z","shell.execute_reply.started":"2023-11-11T16:30:35.586604Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:31:01.491035Z","iopub.status.busy":"2023-11-11T16:31:01.490504Z","iopub.status.idle":"2023-11-11T16:31:01.523089Z","shell.execute_reply":"2023-11-11T16:31:01.521762Z","shell.execute_reply.started":"2023-11-11T16:31:01.490996Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=df.drop(columns=[\"label\"])\ny=df[\"label\"]","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:32:22.011995Z","iopub.status.busy":"2023-11-11T16:32:22.011555Z","iopub.status.idle":"2023-11-11T16:32:22.495153Z","shell.execute_reply":"2023-11-11T16:32:22.493838Z","shell.execute_reply.started":"2023-11-11T16:32:22.011952Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.iloc[0]","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:32:31.488410Z","iopub.status.busy":"2023-11-11T16:32:31.487979Z","iopub.status.idle":"2023-11-11T16:32:31.498437Z","shell.execute_reply":"2023-11-11T16:32:31.497224Z","shell.execute_reply.started":"2023-11-11T16:32:31.488378Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:33:35.331273Z","iopub.status.busy":"2023-11-11T16:33:35.330800Z","iopub.status.idle":"2023-11-11T16:33:35.341086Z","shell.execute_reply":"2023-11-11T16:33:35.339777Z","shell.execute_reply.started":"2023-11-11T16:33:35.331235Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:37:18.523164Z","iopub.status.busy":"2023-11-11T16:37:18.522607Z","iopub.status.idle":"2023-11-11T16:37:19.294497Z","shell.execute_reply":"2023-11-11T16:37:19.292992Z","shell.execute_reply.started":"2023-11-11T16:37:18.523118Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.iloc[0].value_counts()","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:38:41.126910Z","iopub.status.busy":"2023-11-11T16:38:41.126413Z","iopub.status.idle":"2023-11-11T16:38:41.143107Z","shell.execute_reply":"2023-11-11T16:38:41.141847Z","shell.execute_reply.started":"2023-11-11T16:38:41.126872Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train=x_train/255\nx_test=x_test/255","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:41:47.913551Z","iopub.status.busy":"2023-11-11T16:41:47.913055Z","iopub.status.idle":"2023-11-11T16:41:47.990808Z","shell.execute_reply":"2023-11-11T16:41:47.989782Z","shell.execute_reply.started":"2023-11-11T16:41:47.913517Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.iloc[0].value_counts()","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:43:04.372332Z","iopub.status.busy":"2023-11-11T16:43:04.371575Z","iopub.status.idle":"2023-11-11T16:43:04.384981Z","shell.execute_reply":"2023-11-11T16:43:04.383825Z","shell.execute_reply.started":"2023-11-11T16:43:04.372292Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:47:03.698822Z","iopub.status.busy":"2023-11-11T16:47:03.698282Z","iopub.status.idle":"2023-11-11T16:47:03.706857Z","shell.execute_reply":"2023-11-11T16:47:03.705708Z","shell.execute_reply.started":"2023-11-11T16:47:03.698785Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Dense(128,activation=\"relu\",input_dim=784))\nmodel.add(Dense(32,activation=\"relu\"))\nmodel.add(Dense(10,activation=\"softmax\"))\n","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:58:02.798449Z","iopub.status.busy":"2023-11-11T16:58:02.798029Z","iopub.status.idle":"2023-11-11T16:58:02.853642Z","shell.execute_reply":"2023-11-11T16:58:02.852461Z","shell.execute_reply.started":"2023-11-11T16:58:02.798418Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:58:08.032692Z","iopub.status.busy":"2023-11-11T16:58:08.032239Z","iopub.status.idle":"2023-11-11T16:58:08.057836Z","shell.execute_reply":"2023-11-11T16:58:08.056185Z","shell.execute_reply.started":"2023-11-11T16:58:08.032656Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss=\"sparse_categorical_crossentropy\",optimizer=\"Adam\")","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:58:13.393063Z","iopub.status.busy":"2023-11-11T16:58:13.392656Z","iopub.status.idle":"2023-11-11T16:58:13.408599Z","shell.execute_reply":"2023-11-11T16:58:13.407322Z","shell.execute_reply.started":"2023-11-11T16:58:13.393033Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train,epochs=25,validation_split=0.2)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T16:58:20.433461Z","iopub.status.busy":"2023-11-11T16:58:20.433059Z","iopub.status.idle":"2023-11-11T17:00:43.330992Z","shell.execute_reply":"2023-11-11T17:00:43.329681Z","shell.execute_reply.started":"2023-11-11T16:58:20.433431Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_prob=model.predict(x_test)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:00:43.333554Z","iopub.status.busy":"2023-11-11T17:00:43.333222Z","iopub.status.idle":"2023-11-11T17:00:44.097183Z","shell.execute_reply":"2023-11-11T17:00:44.095855Z","shell.execute_reply.started":"2023-11-11T17:00:43.333526Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=y_prob.argmax(axis=1)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:00:47.563087Z","iopub.status.busy":"2023-11-11T17:00:47.562664Z","iopub.status.idle":"2023-11-11T17:00:47.568908Z","shell.execute_reply":"2023-11-11T17:00:47.567693Z","shell.execute_reply.started":"2023-11-11T17:00:47.563054Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:00:50.498400Z","iopub.status.busy":"2023-11-11T17:00:50.497946Z","iopub.status.idle":"2023-11-11T17:00:50.509073Z","shell.execute_reply":"2023-11-11T17:00:50.507905Z","shell.execute_reply.started":"2023-11-11T17:00:50.498366Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_res=model.predict(test)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:02:26.194030Z","iopub.status.busy":"2023-11-11T17:02:26.193542Z","iopub.status.idle":"2023-11-11T17:02:28.569246Z","shell.execute_reply":"2023-11-11T17:02:28.568093Z","shell.execute_reply.started":"2023-11-11T17:02:26.193986Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_res","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:02:32.793063Z","iopub.status.busy":"2023-11-11T17:02:32.792654Z","iopub.status.idle":"2023-11-11T17:02:32.801759Z","shell.execute_reply":"2023-11-11T17:02:32.800217Z","shell.execute_reply.started":"2023-11-11T17:02:32.793032Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_res=y_res.argmax(axis=1)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:02:59.974380Z","iopub.status.busy":"2023-11-11T17:02:59.973026Z","iopub.status.idle":"2023-11-11T17:02:59.980189Z","shell.execute_reply":"2023-11-11T17:02:59.978688Z","shell.execute_reply.started":"2023-11-11T17:02:59.974336Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_res","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:03:04.232395Z","iopub.status.busy":"2023-11-11T17:03:04.231922Z","iopub.status.idle":"2023-11-11T17:03:04.241106Z","shell.execute_reply":"2023-11-11T17:03:04.239515Z","shell.execute_reply.started":"2023-11-11T17:03:04.232359Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample=pd.read_csv(\"/kaggle/input/digit-recognizer/sample_submission.csv\")","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:03:43.672881Z","iopub.status.busy":"2023-11-11T17:03:43.672430Z","iopub.status.idle":"2023-11-11T17:03:43.707948Z","shell.execute_reply":"2023-11-11T17:03:43.706815Z","shell.execute_reply.started":"2023-11-11T17:03:43.672851Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:04:38.832671Z","iopub.status.busy":"2023-11-11T17:04:38.832217Z","iopub.status.idle":"2023-11-11T17:04:38.847610Z","shell.execute_reply":"2023-11-11T17:04:38.846532Z","shell.execute_reply.started":"2023-11-11T17:04:38.832635Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:04:02.433127Z","iopub.status.busy":"2023-11-11T17:04:02.432685Z","iopub.status.idle":"2023-11-11T17:04:02.439893Z","shell.execute_reply":"2023-11-11T17:04:02.438745Z","shell.execute_reply.started":"2023-11-11T17:04:02.433093Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i=sample[\"ImageId\"].to_list()","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:12:25.693903Z","iopub.status.busy":"2023-11-11T17:12:25.692582Z","iopub.status.idle":"2023-11-11T17:12:25.701809Z","shell.execute_reply":"2023-11-11T17:12:25.700265Z","shell.execute_reply.started":"2023-11-11T17:12:25.693851Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"out={\"ImageId\":i,\"Label\":y_res}\nd_out=pd.DataFrame(out)\nd_out.to_csv(\"Output1.csv\",index=False)","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:19:42.938545Z","iopub.status.busy":"2023-11-11T17:19:42.937873Z","iopub.status.idle":"2023-11-11T17:19:43.024128Z","shell.execute_reply":"2023-11-11T17:19:43.023253Z","shell.execute_reply.started":"2023-11-11T17:19:42.938500Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"read=pd.read_csv(\"/kaggle/working/Output1.csv\")","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:19:46.192885Z","iopub.status.busy":"2023-11-11T17:19:46.192411Z","iopub.status.idle":"2023-11-11T17:19:46.206107Z","shell.execute_reply":"2023-11-11T17:19:46.204811Z","shell.execute_reply.started":"2023-11-11T17:19:46.192851Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"read","metadata":{"execution":{"iopub.execute_input":"2023-11-11T17:19:48.352467Z","iopub.status.busy":"2023-11-11T17:19:48.352060Z","iopub.status.idle":"2023-11-11T17:19:48.365190Z","shell.execute_reply":"2023-11-11T17:19:48.363847Z","shell.execute_reply.started":"2023-11-11T17:19:48.352435Z"}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}