{"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":"2022-07-17T11:07:06.470579Z","iopub.execute_input":"2022-07-17T11:07:06.470936Z","iopub.status.idle":"2022-07-17T11:07:06.487121Z","shell.execute_reply.started":"2022-07-17T11:07:06.470906Z","shell.execute_reply":"2022-07-17T11:07:06.485793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:06.494323Z","iopub.execute_input":"2022-07-17T11:07:06.494615Z","iopub.status.idle":"2022-07-17T11:07:06.501619Z","shell.execute_reply.started":"2022-07-17T11:07:06.494590Z","shell.execute_reply":"2022-07-17T11:07:06.500513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('../input/digit-recognizer/train.csv')\ntest_data = pd.read_csv('../input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:06.506754Z","iopub.execute_input":"2022-07-17T11:07:06.507709Z","iopub.status.idle":"2022-07-17T11:07:10.927237Z","shell.execute_reply.started":"2022-07-17T11:07:06.507487Z","shell.execute_reply":"2022-07-17T11:07:10.926152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:10.929237Z","iopub.execute_input":"2022-07-17T11:07:10.929713Z","iopub.status.idle":"2022-07-17T11:07:10.946576Z","shell.execute_reply.started":"2022-07-17T11:07:10.929667Z","shell.execute_reply":"2022-07-17T11:07:10.945330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train_data.drop(['label'],axis=1)\ny_train = train_data['label']\nX_test = test_data","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:10.948353Z","iopub.execute_input":"2022-07-17T11:07:10.948769Z","iopub.status.idle":"2022-07-17T11:07:11.037322Z","shell.execute_reply.started":"2022-07-17T11:07:10.948731Z","shell.execute_reply":"2022-07-17T11:07:11.036245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:11.040154Z","iopub.execute_input":"2022-07-17T11:07:11.040555Z","iopub.status.idle":"2022-07-17T11:07:11.047019Z","shell.execute_reply.started":"2022-07-17T11:07:11.040515Z","shell.execute_reply":"2022-07-17T11:07:11.045803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:11.048737Z","iopub.execute_input":"2022-07-17T11:07:11.049258Z","iopub.status.idle":"2022-07-17T11:07:11.058344Z","shell.execute_reply.started":"2022-07-17T11:07:11.049216Z","shell.execute_reply":"2022-07-17T11:07:11.057260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:11.060026Z","iopub.execute_input":"2022-07-17T11:07:11.060842Z","iopub.status.idle":"2022-07-17T11:07:11.069591Z","shell.execute_reply.started":"2022-07-17T11:07:11.060803Z","shell.execute_reply":"2022-07-17T11:07:11.068393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model =  keras.Sequential([\n                  keras.layers.Dense(10,input_shape=(784,),activation='sigmoid')\n])\n\nmodel.compile(\n    optimizer='adam',\n    loss='sparse_categorical_crossentropy',\n    metrics=['accuracy']\n)\n\nmodel.fit(X_train,y_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:11.070859Z","iopub.execute_input":"2022-07-17T11:07:11.071944Z","iopub.status.idle":"2022-07-17T11:07:24.417245Z","shell.execute_reply.started":"2022-07-17T11:07:11.071907Z","shell.execute_reply":"2022-07-17T11:07:24.416264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_val = model.predict(X_test)\ny_pred_val[10]","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:24.418588Z","iopub.execute_input":"2022-07-17T11:07:24.419388Z","iopub.status.idle":"2022-07-17T11:07:25.564232Z","shell.execute_reply.started":"2022-07-17T11:07:24.419346Z","shell.execute_reply":"2022-07-17T11:07:25.563153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.argmax(y_pred_val[10])","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.565753Z","iopub.execute_input":"2022-07-17T11:07:25.566406Z","iopub.status.idle":"2022-07-17T11:07:25.574474Z","shell.execute_reply.started":"2022-07-17T11:07:25.566363Z","shell.execute_reply":"2022-07-17T11:07:25.573066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred=[np.argmax(i) for i in y_pred_val]\ny_pred[0]","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.578686Z","iopub.execute_input":"2022-07-17T11:07:25.579233Z","iopub.status.idle":"2022-07-17T11:07:25.658682Z","shell.execute_reply.started":"2022-07-17T11:07:25.579163Z","shell.execute_reply":"2022-07-17T11:07:25.657353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(y_pred)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.660345Z","iopub.execute_input":"2022-07-17T11:07:25.660738Z","iopub.status.idle":"2022-07-17T11:07:25.668303Z","shell.execute_reply.started":"2022-07-17T11:07:25.660701Z","shell.execute_reply":"2022-07-17T11:07:25.666384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_id = pd.Series(range(1,28001),name='ImageId')\nimage_id.isnull().sum()\nimage_id.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.670004Z","iopub.execute_input":"2022-07-17T11:07:25.671098Z","iopub.status.idle":"2022-07-17T11:07:25.680676Z","shell.execute_reply.started":"2022-07-17T11:07:25.670997Z","shell.execute_reply":"2022-07-17T11:07:25.679464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = pd.Series(y_pred,name='Label')\ny_pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.682107Z","iopub.execute_input":"2022-07-17T11:07:25.683433Z","iopub.status.idle":"2022-07-17T11:07:25.708922Z","shell.execute_reply.started":"2022-07-17T11:07:25.683385Z","shell.execute_reply":"2022-07-17T11:07:25.707756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = pd.concat([image_id,y_pred],axis=1)\ny_pred.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.710593Z","iopub.execute_input":"2022-07-17T11:07:25.711273Z","iopub.status.idle":"2022-07-17T11:07:25.723567Z","shell.execute_reply.started":"2022-07-17T11:07:25.711228Z","shell.execute_reply":"2022-07-17T11:07:25.722386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.725406Z","iopub.execute_input":"2022-07-17T11:07:25.725835Z","iopub.status.idle":"2022-07-17T11:07:25.735779Z","shell.execute_reply.started":"2022-07-17T11:07:25.725799Z","shell.execute_reply":"2022-07-17T11:07:25.734428Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-17T11:07:25.737152Z","iopub.execute_input":"2022-07-17T11:07:25.738298Z","iopub.status.idle":"2022-07-17T11:07:25.783486Z","shell.execute_reply.started":"2022-07-17T11:07:25.738258Z","shell.execute_reply":"2022-07-17T11:07:25.782584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}