{"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-09-26T07:57:51.502589Z","iopub.execute_input":"2022-09-26T07:57:51.503183Z","iopub.status.idle":"2022-09-26T07:57:51.536235Z","shell.execute_reply.started":"2022-09-26T07:57:51.503056Z","shell.execute_reply":"2022-09-26T07:57:51.535072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ndata.head()","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:57:51.538271Z","iopub.execute_input":"2022-09-26T07:57:51.538561Z","iopub.status.idle":"2022-09-26T07:57:55.685504Z","shell.execute_reply.started":"2022-09-26T07:57:51.538526Z","shell.execute_reply":"2022-09-26T07:57:55.684323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.imshow(data.iloc[4,1:].to_numpy().reshape(28,28))","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:57:55.687153Z","iopub.execute_input":"2022-09-26T07:57:55.687436Z","iopub.status.idle":"2022-09-26T07:57:55.943329Z","shell.execute_reply.started":"2022-09-26T07:57:55.687404Z","shell.execute_reply":"2022-09-26T07:57:55.942470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.iloc[50,1:].to_numpy().reshape(1,784)","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:57:55.945931Z","iopub.execute_input":"2022-09-26T07:57:55.946258Z","iopub.status.idle":"2022-09-26T07:57:55.957188Z","shell.execute_reply.started":"2022-09-26T07:57:55.946226Z","shell.execute_reply":"2022-09-26T07:57:55.956177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"x = data.drop(columns=['label'])\ny = data.label","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:57:55.959104Z","iopub.execute_input":"2022-09-26T07:57:55.959905Z","iopub.status.idle":"2022-09-26T07:57:56.106452Z","shell.execute_reply.started":"2022-09-26T07:57:55.959860Z","shell.execute_reply":"2022-09-26T07:57:56.105143Z"},"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.3)","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:57:56.108064Z","iopub.execute_input":"2022-09-26T07:57:56.108886Z","iopub.status.idle":"2022-09-26T07:57:57.593012Z","shell.execute_reply.started":"2022-09-26T07:57:56.108829Z","shell.execute_reply":"2022-09-26T07:57:57.592028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n%load_ext tensorboard","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:57:57.594465Z","iopub.execute_input":"2022-09-26T07:57:57.594742Z","iopub.status.idle":"2022-09-26T07:58:03.422796Z","shell.execute_reply.started":"2022-09-26T07:57:57.594711Z","shell.execute_reply":"2022-09-26T07:58:03.421868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential \nfrom tensorflow.keras.layers import Dense\nmodel = Sequential()\n\nmodel.add(Dense(4,activation='sigmoid',input_shape=(784,)))\nmodel.add(Dense(5,activation='relu'))\nmodel.add(Dense(3,activation='softmax'))\n\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:58:03.424436Z","iopub.execute_input":"2022-09-26T07:58:03.424686Z","iopub.status.idle":"2022-09-26T07:58:04.702681Z","shell.execute_reply.started":"2022-09-26T07:58:03.424654Z","shell.execute_reply":"2022-09-26T07:58:04.701822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras\n(x_train,y_train),(x_test,y_test)=keras.datasets.mnist.load_data()","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:58:04.704032Z","iopub.execute_input":"2022-09-26T07:58:04.704279Z","iopub.status.idle":"2022-09-26T07:58:05.270513Z","shell.execute_reply.started":"2022-09-26T07:58:04.704249Z","shell.execute_reply":"2022-09-26T07:58:05.269388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_train[1])","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:58:05.273488Z","iopub.execute_input":"2022-09-26T07:58:05.273762Z","iopub.status.idle":"2022-09-26T07:58:05.493462Z","shell.execute_reply.started":"2022-09-26T07:58:05.273732Z","shell.execute_reply":"2022-09-26T07:58:05.492249Z"},"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()\n\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'))\n\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:58:05.495299Z","iopub.execute_input":"2022-09-26T07:58:05.495666Z","iopub.status.idle":"2022-09-26T07:58:05.546037Z","shell.execute_reply.started":"2022-09-26T07:58:05.495622Z","shell.execute_reply":"2022-09-26T07:58:05.544948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss = 'sparse_categorical_crossentropy',optimizer = 'adam',metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:58:05.548199Z","iopub.execute_input":"2022-09-26T07:58:05.549013Z","iopub.status.idle":"2022-09-26T07:58:05.565391Z","shell.execute_reply.started":"2022-09-26T07:58:05.548922Z","shell.execute_reply":"2022-09-26T07:58:05.564590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train,epochs=50)","metadata":{"execution":{"iopub.status.busy":"2022-09-26T07:58:05.567145Z","iopub.execute_input":"2022-09-26T07:58:05.567417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=model.predict(x_train)\npred","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred.argmax(axis=1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.predict(x_test[1].reshape(1,28,28)).argmax(axis=1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_test[1])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}