{"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-04-11T08:40:12.173559Z","iopub.execute_input":"2022-04-11T08:40:12.173814Z","iopub.status.idle":"2022-04-11T08:40:12.182511Z","shell.execute_reply.started":"2022-04-11T08:40:12.173784Z","shell.execute_reply":"2022-04-11T08:40:12.181834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data= pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ndata","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:12.183822Z","iopub.execute_input":"2022-04-11T08:40:12.184062Z","iopub.status.idle":"2022-04-11T08:40:15.544162Z","shell.execute_reply.started":"2022-04-11T08:40:12.184033Z","shell.execute_reply":"2022-04-11T08:40:15.543520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:15.545243Z","iopub.execute_input":"2022-04-11T08:40:15.545516Z","iopub.status.idle":"2022-04-11T08:40:15.551791Z","shell.execute_reply.started":"2022-04-11T08:40:15.545460Z","shell.execute_reply":"2022-04-11T08:40:15.550589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(data.iloc[0,1:].to_numpy().reshape(28,28))","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:15.553282Z","iopub.execute_input":"2022-04-11T08:40:15.554288Z","iopub.status.idle":"2022-04-11T08:40:15.771841Z","shell.execute_reply.started":"2022-04-11T08:40:15.554230Z","shell.execute_reply":"2022-04-11T08:40:15.770571Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x= data.drop(columns=['label'])\nx","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:15.773514Z","iopub.execute_input":"2022-04-11T08:40:15.774064Z","iopub.status.idle":"2022-04-11T08:40:15.899988Z","shell.execute_reply.started":"2022-04-11T08:40:15.774027Z","shell.execute_reply":"2022-04-11T08:40:15.899088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y= data['label']\ny","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:15.901564Z","iopub.execute_input":"2022-04-11T08:40:15.902043Z","iopub.status.idle":"2022-04-11T08:40:15.910043Z","shell.execute_reply.started":"2022-04-11T08:40:15.902001Z","shell.execute_reply":"2022-04-11T08:40:15.908973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:15.911370Z","iopub.execute_input":"2022-04-11T08:40:15.911647Z","iopub.status.idle":"2022-04-11T08:40:15.921875Z","shell.execute_reply.started":"2022-04-11T08:40:15.911618Z","shell.execute_reply":"2022-04-11T08:40:15.921212Z"},"trusted":true},"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.status.busy":"2022-04-11T08:40:15.923239Z","iopub.execute_input":"2022-04-11T08:40:15.923684Z","iopub.status.idle":"2022-04-11T08:40:16.304839Z","shell.execute_reply.started":"2022-04-11T08:40:15.923639Z","shell.execute_reply":"2022-04-11T08:40:16.303722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense \nmodel = Sequential()\nmodel.add(Dense(3,activation = 'sigmoid',input_shape = (784,))) \nmodel.add(Dense(2,activation = 'relu'))\nmodel.add(Dense(1,activation = 'softmax'))\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.306068Z","iopub.execute_input":"2022-04-11T08:40:16.306319Z","iopub.status.idle":"2022-04-11T08:40:16.347393Z","shell.execute_reply.started":"2022-04-11T08:40:16.306289Z","shell.execute_reply":"2022-04-11T08:40:16.346544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.349087Z","iopub.execute_input":"2022-04-11T08:40:16.349343Z","iopub.status.idle":"2022-04-11T08:40:16.353610Z","shell.execute_reply.started":"2022-04-11T08:40:16.349311Z","shell.execute_reply":"2022-04-11T08:40:16.352772Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(x_train,y_train),(x_test,y_test) = keras.datasets.mnist.load_data()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.354966Z","iopub.execute_input":"2022-04-11T08:40:16.355202Z","iopub.status.idle":"2022-04-11T08:40:16.694654Z","shell.execute_reply.started":"2022-04-11T08:40:16.355172Z","shell.execute_reply":"2022-04-11T08:40:16.693703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.695991Z","iopub.execute_input":"2022-04-11T08:40:16.696240Z","iopub.status.idle":"2022-04-11T08:40:16.702191Z","shell.execute_reply.started":"2022-04-11T08:40:16.696209Z","shell.execute_reply":"2022-04-11T08:40:16.701337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_train[1])","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.703447Z","iopub.execute_input":"2022-04-11T08:40:16.703727Z","iopub.status.idle":"2022-04-11T08:40:16.920195Z","shell.execute_reply.started":"2022-04-11T08:40:16.703696Z","shell.execute_reply":"2022-04-11T08:40:16.918980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense,Flatten\nmodel = Sequential()\nmodel.add(Flatten(input_shape=(28,28)))\nmodel.add(Dense(4,activation = 'sigmoid'))\nmodel.add(Dense(5,activation = 'relu'))\nmodel.add(Dense(10,activation = 'softmax'))\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.922341Z","iopub.execute_input":"2022-04-11T08:40:16.923089Z","iopub.status.idle":"2022-04-11T08:40:16.966115Z","shell.execute_reply.started":"2022-04-11T08:40:16.923047Z","shell.execute_reply":"2022-04-11T08:40:16.965521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nmodel.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.967327Z","iopub.execute_input":"2022-04-11T08:40:16.968138Z","iopub.status.idle":"2022-04-11T08:40:16.980505Z","shell.execute_reply.started":"2022-04-11T08:40:16.968098Z","shell.execute_reply":"2022-04-11T08:40:16.979729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train,epochs=5)","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:16.982110Z","iopub.execute_input":"2022-04-11T08:40:16.982774Z","iopub.status.idle":"2022-04-11T08:40:38.574715Z","shell.execute_reply.started":"2022-04-11T08:40:16.982725Z","shell.execute_reply":"2022-04-11T08:40:38.573581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=model.predict(x_train)\npred","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:38.580280Z","iopub.execute_input":"2022-04-11T08:40:38.580571Z","iopub.status.idle":"2022-04-11T08:40:40.858923Z","shell.execute_reply.started":"2022-04-11T08:40:38.580535Z","shell.execute_reply":"2022-04-11T08:40:40.857845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred.argmax(axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:40:40.860610Z","iopub.execute_input":"2022-04-11T08:40:40.860953Z","iopub.status.idle":"2022-04-11T08:40:40.871013Z","shell.execute_reply.started":"2022-04-11T08:40:40.860908Z","shell.execute_reply":"2022-04-11T08:40:40.869367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.predict(x_test[1].reshape(1,28,28)).argmax(axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:41:32.213274Z","iopub.execute_input":"2022-04-11T08:41:32.214341Z","iopub.status.idle":"2022-04-11T08:41:32.326185Z","shell.execute_reply.started":"2022-04-11T08:41:32.214302Z","shell.execute_reply":"2022-04-11T08:41:32.325473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_test[1])","metadata":{"execution":{"iopub.status.busy":"2022-04-11T08:41:34.583597Z","iopub.execute_input":"2022-04-11T08:41:34.583938Z","iopub.status.idle":"2022-04-11T08:41:34.793137Z","shell.execute_reply.started":"2022-04-11T08:41:34.583873Z","shell.execute_reply":"2022-04-11T08:41:34.792266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}