{"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-13T03:57:59.782874Z","iopub.execute_input":"2022-04-13T03:57:59.783277Z","iopub.status.idle":"2022-04-13T03:57:59.819284Z","shell.execute_reply.started":"2022-04-13T03:57:59.783173Z","shell.execute_reply":"2022-04-13T03:57:59.818556Z"},"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-13T03:57:59.822174Z","iopub.execute_input":"2022-04-13T03:57:59.822709Z","iopub.status.idle":"2022-04-13T03:58:04.098842Z","shell.execute_reply.started":"2022-04-13T03:57:59.822670Z","shell.execute_reply":"2022-04-13T03:58:04.098178Z"},"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-13T03:58:04.100099Z","iopub.execute_input":"2022-04-13T03:58:04.100846Z","iopub.status.idle":"2022-04-13T03:58:04.295616Z","shell.execute_reply.started":"2022-04-13T03:58:04.100808Z","shell.execute_reply":"2022-04-13T03:58:04.294647Z"},"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-13T03:58:04.296923Z","iopub.execute_input":"2022-04-13T03:58:04.297138Z","iopub.status.idle":"2022-04-13T03:58:04.307977Z","shell.execute_reply.started":"2022-04-13T03:58:04.297113Z","shell.execute_reply":"2022-04-13T03:58:04.307058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = data.drop(columns = ['label'])\ny = data.label\n    ","metadata":{"execution":{"iopub.status.busy":"2022-04-13T03:58:04.309923Z","iopub.execute_input":"2022-04-13T03:58:04.310178Z","iopub.status.idle":"2022-04-13T03:58:04.439102Z","shell.execute_reply.started":"2022-04-13T03:58:04.310147Z","shell.execute_reply":"2022-04-13T03:58:04.438263Z"},"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-04-13T03:58:04.440543Z","iopub.execute_input":"2022-04-13T03:58:04.440882Z","iopub.status.idle":"2022-04-13T03:58:05.908740Z","shell.execute_reply.started":"2022-04-13T03:58:04.440839Z","shell.execute_reply":"2022-04-13T03:58:05.907720Z"},"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-13T03:58:05.909820Z","iopub.execute_input":"2022-04-13T03:58:05.910063Z","iopub.status.idle":"2022-04-13T03:58:11.177614Z","shell.execute_reply.started":"2022-04-13T03:58:05.910034Z","shell.execute_reply":"2022-04-13T03:58:11.176797Z"},"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-13T03:58:11.178690Z","iopub.execute_input":"2022-04-13T03:58:11.178945Z","iopub.status.idle":"2022-04-13T03:58:12.443568Z","shell.execute_reply.started":"2022-04-13T03:58:11.178914Z","shell.execute_reply":"2022-04-13T03:58:12.442755Z"},"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-13T03:58:12.444844Z","iopub.execute_input":"2022-04-13T03:58:12.445068Z","iopub.status.idle":"2022-04-13T03:58:12.902842Z","shell.execute_reply.started":"2022-04-13T03:58:12.445040Z","shell.execute_reply":"2022-04-13T03:58:12.901704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_train[1])","metadata":{"execution":{"iopub.status.busy":"2022-04-13T03:58:12.904589Z","iopub.execute_input":"2022-04-13T03:58:12.904957Z","iopub.status.idle":"2022-04-13T03:58:13.059747Z","shell.execute_reply.started":"2022-04-13T03:58:12.904912Z","shell.execute_reply":"2022-04-13T03:58:13.058667Z"},"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-13T03:58:13.062853Z","iopub.execute_input":"2022-04-13T03:58:13.063213Z","iopub.status.idle":"2022-04-13T03:58:13.108157Z","shell.execute_reply.started":"2022-04-13T03:58:13.063166Z","shell.execute_reply":"2022-04-13T03:58:13.107054Z"},"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-13T03:58:13.109358Z","iopub.execute_input":"2022-04-13T03:58:13.109598Z","iopub.status.idle":"2022-04-13T03:58:13.126880Z","shell.execute_reply.started":"2022-04-13T03:58:13.109568Z","shell.execute_reply":"2022-04-13T03:58:13.126036Z"},"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-13T03:58:13.128495Z","iopub.execute_input":"2022-04-13T03:58:13.128865Z","iopub.status.idle":"2022-04-13T04:01:29.267940Z","shell.execute_reply.started":"2022-04-13T03:58:13.128821Z","shell.execute_reply":"2022-04-13T04:01:29.266998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\npred=model.predict(x_train)\npred","metadata":{"execution":{"iopub.status.busy":"2022-04-13T04:01:29.269234Z","iopub.execute_input":"2022-04-13T04:01:29.269478Z","iopub.status.idle":"2022-04-13T04:01:31.357583Z","shell.execute_reply.started":"2022-04-13T04:01:29.269449Z","shell.execute_reply":"2022-04-13T04:01:31.356221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred.argmax(axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-04-13T04:01:31.359045Z","iopub.execute_input":"2022-04-13T04:01:31.359389Z","iopub.status.idle":"2022-04-13T04:01:31.367427Z","shell.execute_reply.started":"2022-04-13T04:01:31.359353Z","shell.execute_reply":"2022-04-13T04:01:31.366602Z"},"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-13T04:01:31.369027Z","iopub.execute_input":"2022-04-13T04:01:31.370018Z","iopub.status.idle":"2022-04-13T04:01:31.515945Z","shell.execute_reply.started":"2022-04-13T04:01:31.369971Z","shell.execute_reply":"2022-04-13T04:01:31.514792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_test[1])","metadata":{"execution":{"iopub.status.busy":"2022-04-13T04:01:31.517771Z","iopub.execute_input":"2022-04-13T04:01:31.518876Z","iopub.status.idle":"2022-04-13T04:01:31.693757Z","shell.execute_reply.started":"2022-04-13T04:01:31.518693Z","shell.execute_reply":"2022-04-13T04:01:31.692804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}