{"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-01-31T15:30:50.974321Z","iopub.execute_input":"2023-01-31T15:30:50.974790Z","iopub.status.idle":"2023-01-31T15:30:51.008354Z","shell.execute_reply.started":"2023-01-31T15:30:50.974676Z","shell.execute_reply":"2023-01-31T15:30:51.007208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import pyplot as plt\nimport tensorflow\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense","metadata":{"execution":{"iopub.status.busy":"2023-01-31T16:04:50.679392Z","iopub.execute_input":"2023-01-31T16:04:50.679807Z","iopub.status.idle":"2023-01-31T16:04:50.686813Z","shell.execute_reply.started":"2023-01-31T16:04:50.679776Z","shell.execute_reply":"2023-01-31T16:04:50.685232Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data=pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest_data=pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")\nsample_sub=pd.read_csv(\"/kaggle/input/digit-recognizer/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:51:07.950682Z","iopub.execute_input":"2023-01-31T15:51:07.951072Z","iopub.status.idle":"2023-01-31T15:51:11.177784Z","shell.execute_reply.started":"2023-01-31T15:51:07.951045Z","shell.execute_reply":"2023-01-31T15:51:11.176214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:30:55.969412Z","iopub.execute_input":"2023-01-31T15:30:55.969971Z","iopub.status.idle":"2023-01-31T15:30:55.999940Z","shell.execute_reply.started":"2023-01-31T15:30:55.969932Z","shell.execute_reply":"2023-01-31T15:30:55.998204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head(5)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:30:56.003153Z","iopub.execute_input":"2023-01-31T15:30:56.003925Z","iopub.status.idle":"2023-01-31T15:30:56.023630Z","shell.execute_reply.started":"2023-01-31T15:30:56.003872Z","shell.execute_reply":"2023-01-31T15:30:56.021765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_x=train_data.drop(columns='label')\ntrain_y=train_data['label']","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:30:56.025220Z","iopub.execute_input":"2023-01-31T15:30:56.025980Z","iopub.status.idle":"2023-01-31T15:30:56.101157Z","shell.execute_reply.started":"2023-01-31T15:30:56.025945Z","shell.execute_reply":"2023-01-31T15:30:56.099789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_x.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:31:09.893847Z","iopub.execute_input":"2023-01-31T15:31:09.894201Z","iopub.status.idle":"2023-01-31T15:31:09.903155Z","shell.execute_reply.started":"2023-01-31T15:31:09.894169Z","shell.execute_reply":"2023-01-31T15:31:09.901840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:31:19.005163Z","iopub.execute_input":"2023-01-31T15:31:19.005631Z","iopub.status.idle":"2023-01-31T15:31:19.015758Z","shell.execute_reply.started":"2023-01-31T15:31:19.005594Z","shell.execute_reply":"2023-01-31T15:31:19.013643Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y=to_categorical(train_y,10)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:33:32.936412Z","iopub.execute_input":"2023-01-31T15:33:32.937412Z","iopub.status.idle":"2023-01-31T15:33:32.946976Z","shell.execute_reply.started":"2023-01-31T15:33:32.937378Z","shell.execute_reply":"2023-01-31T15:33:32.944300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_y.shape","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:33:42.049803Z","iopub.execute_input":"2023-01-31T15:33:42.051178Z","iopub.status.idle":"2023-01-31T15:33:42.059593Z","shell.execute_reply.started":"2023-01-31T15:33:42.051094Z","shell.execute_reply":"2023-01-31T15:33:42.057932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model=Sequential()\nmodel.add(Dense(648,activation='relu',input_dim=train_x.shape[1]))\nmodel.add(Dense(80,activation='relu'))\nmodel.add(Dense(10,activation='softmax'))","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:42:58.801085Z","iopub.execute_input":"2023-01-31T15:42:58.801550Z","iopub.status.idle":"2023-01-31T15:42:58.843429Z","shell.execute_reply.started":"2023-01-31T15:42:58.801515Z","shell.execute_reply":"2023-01-31T15:42:58.841072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:43:00.940933Z","iopub.execute_input":"2023-01-31T15:43:00.941353Z","iopub.status.idle":"2023-01-31T15:43:00.949939Z","shell.execute_reply.started":"2023-01-31T15:43:00.941311Z","shell.execute_reply":"2023-01-31T15:43:00.947819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:43:02.749651Z","iopub.execute_input":"2023-01-31T15:43:02.750108Z","iopub.status.idle":"2023-01-31T15:43:02.763486Z","shell.execute_reply.started":"2023-01-31T15:43:02.750075Z","shell.execute_reply":"2023-01-31T15:43:02.761919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit(x=train_x , y=train_y , epochs=25,validation_split=0.2,callbacks=tensorflow.keras.callbacks.EarlyStopping(monitor=\"val_loss\",patience=3))","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:46:32.615159Z","iopub.execute_input":"2023-01-31T15:46:32.615628Z","iopub.status.idle":"2023-01-31T15:47:14.600586Z","shell.execute_reply.started":"2023-01-31T15:46:32.615591Z","shell.execute_reply":"2023-01-31T15:47:14.598949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_prediction=model.predict(test_data)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:49:02.372120Z","iopub.execute_input":"2023-01-31T15:49:02.372506Z","iopub.status.idle":"2023-01-31T15:49:04.860491Z","shell.execute_reply.started":"2023-01-31T15:49:02.372472Z","shell.execute_reply":"2023-01-31T15:49:04.858831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=np.argmax(y_prediction,axis=1)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:49:39.327157Z","iopub.execute_input":"2023-01-31T15:49:39.327616Z","iopub.status.idle":"2023-01-31T15:49:39.334331Z","shell.execute_reply.started":"2023-01-31T15:49:39.327580Z","shell.execute_reply":"2023-01-31T15:49:39.332916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:51:25.000181Z","iopub.execute_input":"2023-01-31T15:51:25.000617Z","iopub.status.idle":"2023-01-31T15:51:25.008432Z","shell.execute_reply.started":"2023-01-31T15:51:25.000584Z","shell.execute_reply":"2023-01-31T15:51:25.007418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub.Label = y_pred\nsample_sub.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-31T15:51:16.865125Z","iopub.execute_input":"2023-01-31T15:51:16.865580Z","iopub.status.idle":"2023-01-31T15:51:16.878627Z","shell.execute_reply.started":"2023-01-31T15:51:16.865542Z","shell.execute_reply":"2023-01-31T15:51:16.877484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub.to_csv(\"Submission.csv\", index=False, header=True)","metadata":{"execution":{"iopub.status.busy":"2023-01-31T16:01:54.289159Z","iopub.execute_input":"2023-01-31T16:01:54.289543Z","iopub.status.idle":"2023-01-31T16:01:54.327188Z","shell.execute_reply.started":"2023-01-31T16:01:54.289511Z","shell.execute_reply":"2023-01-31T16:01:54.325031Z"},"trusted":true},"execution_count":null,"outputs":[]}]}