{"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":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-03-28T19:05:58.870326Z","iopub.execute_input":"2023-03-28T19:05:58.870841Z","iopub.status.idle":"2023-03-28T19:05:58.901365Z","shell.execute_reply.started":"2023-03-28T19:05:58.870796Z","shell.execute_reply":"2023-03-28T19:05:58.899962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data= pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\n","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:05:58.90447Z","iopub.execute_input":"2023-03-28T19:05:58.905804Z","iopub.status.idle":"2023-03-28T19:06:02.528062Z","shell.execute_reply.started":"2023-03-28T19:05:58.905729Z","shell.execute_reply":"2023-03-28T19:06:02.524748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels=data.iloc[:,0].values.astype('int32')\ntrain_images=data.iloc[:,1:].values.astype('float32')","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:06:02.533319Z","iopub.execute_input":"2023-03-28T19:06:02.535156Z","iopub.status.idle":"2023-03-28T19:06:02.628178Z","shell.execute_reply.started":"2023-03-28T19:06:02.535074Z","shell.execute_reply":"2023-03-28T19:06:02.626561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images=train_images.reshape(train_images.shape[0],28,28)\nfrom tensorflow import keras","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:06:02.630776Z","iopub.execute_input":"2023-03-28T19:06:02.631532Z","iopub.status.idle":"2023-03-28T19:06:07.402552Z","shell.execute_reply.started":"2023-03-28T19:06:02.631473Z","shell.execute_reply":"2023-03-28T19:06:07.399207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels=keras.utils.to_categorical(train_labels)","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:06:07.410529Z","iopub.execute_input":"2023-03-28T19:06:07.412087Z","iopub.status.idle":"2023-03-28T19:06:07.423648Z","shell.execute_reply.started":"2023-03-28T19:06:07.412007Z","shell.execute_reply":"2023-03-28T19:06:07.421141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images=train_images/255","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:06:07.427073Z","iopub.execute_input":"2023-03-28T19:06:07.427969Z","iopub.status.idle":"2023-03-28T19:06:07.511311Z","shell.execute_reply.started":"2023-03-28T19:06:07.427814Z","shell.execute_reply":"2023-03-28T19:06:07.509009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import Sequential,layers\nmodel=Sequential([\n    layers.Dense(units=64,activation='relu',input_shape=train_images[0].shape),\n    layers.Dropout(0.1),\n    layers.Dense(units=32,activation='relu'),\n    layers.Dropout(0.1),\n    layers.Flatten(),\n    layers.Dense(10,activation='softmax')\n])\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:12:16.506192Z","iopub.execute_input":"2023-03-28T19:12:16.506859Z","iopub.status.idle":"2023-03-28T19:12:16.649086Z","shell.execute_reply.started":"2023-03-28T19:12:16.506811Z","shell.execute_reply":"2023-03-28T19:12:16.647116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])\nmodel.fit(train_images,train_labels,\n                 batch_size=64,\n                 epochs=20,\n                 verbose=1,\n                 )","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:13:47.09976Z","iopub.execute_input":"2023-03-28T19:13:47.100253Z","iopub.status.idle":"2023-03-28T19:14:00.735056Z","shell.execute_reply.started":"2023-03-28T19:13:47.100212Z","shell.execute_reply":"2023-03-28T19:14:00.732303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_images=pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\ntest_images=test_images.iloc[:,:].values.astype('float32')","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:06:58.114088Z","iopub.execute_input":"2023-03-28T19:06:58.114739Z","iopub.status.idle":"2023-03-28T19:07:00.340414Z","shell.execute_reply.started":"2023-03-28T19:06:58.114682Z","shell.execute_reply":"2023-03-28T19:07:00.338116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_images=test_images.reshape(test_images.shape[0],28,28)","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:07:00.342761Z","iopub.execute_input":"2023-03-28T19:07:00.344326Z","iopub.status.idle":"2023-03-28T19:07:00.354004Z","shell.execute_reply.started":"2023-03-28T19:07:00.344237Z","shell.execute_reply":"2023-03-28T19:07:00.351759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = np.argmax(model.predict(test_images, verbose=0),axis=1)\n\nsubmissions=pd.DataFrame({\"ImageId\": list(range(1,len(predictions)+1)),\n                         \"Label\": predictions})\nsubmissions.to_csv(\"submission.csv\", index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:07:28.193987Z","iopub.execute_input":"2023-03-28T19:07:28.194574Z","iopub.status.idle":"2023-03-28T19:07:31.176796Z","shell.execute_reply.started":"2023-03-28T19:07:28.194532Z","shell.execute_reply":"2023-03-28T19:07:31.17497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=pd.read_csv('/kaggle/working/DR.csv')\ndata.head","metadata":{"execution":{"iopub.status.busy":"2023-03-28T19:07:31.425365Z","iopub.execute_input":"2023-03-28T19:07:31.426144Z","iopub.status.idle":"2023-03-28T19:07:31.45562Z","shell.execute_reply.started":"2023-03-28T19:07:31.426083Z","shell.execute_reply":"2023-03-28T19:07:31.453973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}