{"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-08T14:36:55.508446Z","iopub.execute_input":"2022-04-08T14:36:55.508802Z","iopub.status.idle":"2022-04-08T14:36:55.519577Z","shell.execute_reply.started":"2022-04-08T14:36:55.508768Z","shell.execute_reply":"2022-04-08T14:36:55.518563Z"},"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-08T14:36:55.523031Z","iopub.execute_input":"2022-04-08T14:36:55.523733Z","iopub.status.idle":"2022-04-08T14:37:00.577826Z","shell.execute_reply.started":"2022-04-08T14:36:55.52368Z","shell.execute_reply":"2022-04-08T14:37:00.576877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt \nplt.imshow(data.iloc[0,1:].to_numpy().reshape(28,28))    #to get the image ","metadata":{"execution":{"iopub.status.busy":"2022-04-08T14:37:00.579776Z","iopub.execute_input":"2022-04-08T14:37:00.580052Z","iopub.status.idle":"2022-04-08T14:37:00.823125Z","shell.execute_reply.started":"2022-04-08T14:37:00.580019Z","shell.execute_reply":"2022-04-08T14:37:00.822122Z"},"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-04-08T14:37:00.824752Z","iopub.execute_input":"2022-04-08T14:37:00.825082Z","iopub.status.idle":"2022-04-08T14:37:00.836985Z","shell.execute_reply.started":"2022-04-08T14:37:00.825033Z","shell.execute_reply":"2022-04-08T14:37:00.836097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = data.drop(columns = ['label'])\ny = data.label","metadata":{"execution":{"iopub.status.busy":"2022-04-08T14:37:00.838892Z","iopub.execute_input":"2022-04-08T14:37:00.839289Z","iopub.status.idle":"2022-04-08T14:37:00.976285Z","shell.execute_reply.started":"2022-04-08T14:37:00.839232Z","shell.execute_reply":"2022-04-08T14:37:00.975139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"    \nfrom 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-04-08T14:37:00.977852Z","iopub.execute_input":"2022-04-08T14:37:00.978152Z","iopub.status.idle":"2022-04-08T14:37:02.457808Z","shell.execute_reply.started":"2022-04-08T14:37:00.97812Z","shell.execute_reply":"2022-04-08T14:37:02.456859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\n%load_ext tensorboard","metadata":{"execution":{"iopub.status.busy":"2022-04-08T14:37:02.459304Z","iopub.execute_input":"2022-04-08T14:37:02.459783Z","iopub.status.idle":"2022-04-08T14:37:08.507803Z","shell.execute_reply.started":"2022-04-08T14:37:02.459742Z","shell.execute_reply":"2022-04-08T14:37:08.506787Z"},"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-04-08T14:37:08.509171Z","iopub.execute_input":"2022-04-08T14:37:08.50946Z","iopub.status.idle":"2022-04-08T14:37:09.914866Z","shell.execute_reply.started":"2022-04-08T14:37:08.509426Z","shell.execute_reply":"2022-04-08T14:37:09.913804Z"},"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-04-08T14:37:09.91644Z","iopub.execute_input":"2022-04-08T14:37:09.916722Z","iopub.status.idle":"2022-04-08T14:37:10.52846Z","shell.execute_reply.started":"2022-04-08T14:37:09.916687Z","shell.execute_reply":"2022-04-08T14:37:10.527611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_train[1])","metadata":{"execution":{"iopub.status.busy":"2022-04-08T14:37:10.529918Z","iopub.execute_input":"2022-04-08T14:37:10.530432Z","iopub.status.idle":"2022-04-08T14:37:10.742496Z","shell.execute_reply.started":"2022-04-08T14:37:10.530392Z","shell.execute_reply":"2022-04-08T14:37:10.741766Z"},"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-04-08T14:37:10.744771Z","iopub.execute_input":"2022-04-08T14:37:10.745637Z","iopub.status.idle":"2022-04-08T14:37:10.788719Z","shell.execute_reply.started":"2022-04-08T14:37:10.745533Z","shell.execute_reply":"2022-04-08T14:37:10.787872Z"},"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-04-08T14:37:10.78978Z","iopub.execute_input":"2022-04-08T14:37:10.790524Z","iopub.status.idle":"2022-04-08T14:37:10.805511Z","shell.execute_reply.started":"2022-04-08T14:37:10.79049Z","shell.execute_reply":"2022-04-08T14:37:10.804455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(x_train,y_train,epochs=50)","metadata":{"execution":{"iopub.status.busy":"2022-04-08T14:37:10.806869Z","iopub.execute_input":"2022-04-08T14:37:10.807568Z","iopub.status.idle":"2022-04-08T14:40:21.771937Z","shell.execute_reply.started":"2022-04-08T14:37:10.807526Z","shell.execute_reply":"2022-04-08T14:40:21.770865Z"},"trusted":true},"execution_count":null,"outputs":[]}]}