{"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":"from tensorflow import keras\nimport tensorflow as tf\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-12-11T05:59:21.288119Z","iopub.execute_input":"2022-12-11T05:59:21.288553Z","iopub.status.idle":"2022-12-11T05:59:26.246810Z","shell.execute_reply.started":"2022-12-11T05:59:21.288465Z","shell.execute_reply":"2022-12-11T05:59:26.245882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\nX.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:12.337930Z","iopub.execute_input":"2022-12-11T06:06:12.338368Z","iopub.status.idle":"2022-12-11T06:06:14.954059Z","shell.execute_reply.started":"2022-12-11T06:06:12.338331Z","shell.execute_reply":"2022-12-11T06:06:14.953264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = X['label']\nX = X.drop('label', axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:14.955649Z","iopub.execute_input":"2022-12-11T06:06:14.956462Z","iopub.status.idle":"2022-12-11T06:06:15.083309Z","shell.execute_reply.started":"2022-12-11T06:06:14.956428Z","shell.execute_reply":"2022-12-11T06:06:15.082191Z"},"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.1, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:24.132903Z","iopub.execute_input":"2022-12-11T06:06:24.133311Z","iopub.status.idle":"2022-12-11T06:06:24.413779Z","shell.execute_reply.started":"2022-12-11T06:06:24.133278Z","shell.execute_reply":"2022-12-11T06:06:24.412800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(X_train),len(X_test),","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:25.057079Z","iopub.execute_input":"2022-12-11T06:06:25.057506Z","iopub.status.idle":"2022-12-11T06:06:25.065566Z","shell.execute_reply.started":"2022-12-11T06:06:25.057471Z","shell.execute_reply":"2022-12-11T06:06:25.064417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:26.040919Z","iopub.execute_input":"2022-12-11T06:06:26.041500Z","iopub.status.idle":"2022-12-11T06:06:26.046686Z","shell.execute_reply.started":"2022-12-11T06:06:26.041460Z","shell.execute_reply":"2022-12-11T06:06:26.045922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#scaled\nX_train = X_train/255.0\nX_test = X_test/255.0","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:27.156874Z","iopub.execute_input":"2022-12-11T06:06:27.157522Z","iopub.status.idle":"2022-12-11T06:06:27.228089Z","shell.execute_reply.started":"2022-12-11T06:06:27.157469Z","shell.execute_reply":"2022-12-11T06:06:27.227276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_flattened.shape,X_test_flattened.shape,","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:29.362484Z","iopub.execute_input":"2022-12-11T06:06:29.363105Z","iopub.status.idle":"2022-12-11T06:06:29.371291Z","shell.execute_reply.started":"2022-12-11T06:06:29.363055Z","shell.execute_reply":"2022-12-11T06:06:29.370218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = keras.models.Sequential([\n    keras.layers.Flatten(input_shape=(28,28)),\n    keras.layers.Dense(128,activation=\"relu\"),\n    keras.layers.Dense(10,activation=\"sigmoid\")\n])\ntb_callback = tf.keras.callbacks.TensorBoard(log_dir =\"log_dir/\",histogram_freq =1)\nmodel.compile(optimizer=\"sgd\",\n              loss=\"sparse_categorical_crossentropy\",\n              metrics=['accuracy'])\nmodel.fit(X_train,y_train,epochs=5, validation_data=(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:06:56.819179Z","iopub.execute_input":"2022-12-11T06:06:56.819592Z","iopub.status.idle":"2022-12-11T06:07:09.277131Z","shell.execute_reply.started":"2022-12-11T06:06:56.819559Z","shell.execute_reply":"2022-12-11T06:07:09.275901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:07:26.067172Z","iopub.execute_input":"2022-12-11T06:07:26.067802Z","iopub.status.idle":"2022-12-11T06:07:28.196629Z","shell.execute_reply.started":"2022-12-11T06:07:26.067764Z","shell.execute_reply":"2022-12-11T06:07:28.195242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(df/255)","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:10:52.371461Z","iopub.execute_input":"2022-12-11T06:10:52.372304Z","iopub.status.idle":"2022-12-11T06:10:53.841415Z","shell.execute_reply.started":"2022-12-11T06:10:52.372263Z","shell.execute_reply":"2022-12-11T06:10:53.840364Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred= [np.argmax(i) for i in y_pred]","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:10:54.646263Z","iopub.execute_input":"2022-12-11T06:10:54.647542Z","iopub.status.idle":"2022-12-11T06:10:54.703739Z","shell.execute_reply.started":"2022-12-11T06:10:54.647501Z","shell.execute_reply":"2022-12-11T06:10:54.702619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Label'] = y_pred","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:11:46.559577Z","iopub.execute_input":"2022-12-11T06:11:46.559956Z","iopub.status.idle":"2022-12-11T06:11:46.575229Z","shell.execute_reply.started":"2022-12-11T06:11:46.559925Z","shell.execute_reply":"2022-12-11T06:11:46.574028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = df[['Label']]\nsubmission = submission.reset_index()\nsubmission.columns = ['ImageId','Label']\nsubmission['ImageId'] = submission['ImageId'] + 1","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:17:44.291929Z","iopub.execute_input":"2022-12-11T06:17:44.292354Z","iopub.status.idle":"2022-12-11T06:17:44.300611Z","shell.execute_reply.started":"2022-12-11T06:17:44.292319Z","shell.execute_reply":"2022-12-11T06:17:44.299606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:17:51.271799Z","iopub.execute_input":"2022-12-11T06:17:51.272198Z","iopub.status.idle":"2022-12-11T06:17:51.288994Z","shell.execute_reply.started":"2022-12-11T06:17:51.272163Z","shell.execute_reply":"2022-12-11T06:17:51.287745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-11T06:17:54.355415Z","iopub.execute_input":"2022-12-11T06:17:54.355788Z","iopub.status.idle":"2022-12-11T06:17:54.391160Z","shell.execute_reply.started":"2022-12-11T06:17:54.355757Z","shell.execute_reply":"2022-12-11T06:17:54.390294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%load_ext tensorboard\n%tensorboard --logdir logs/fit","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-11-22T02:37:45.287956Z","iopub.execute_input":"2022-11-22T02:37:45.288230Z","iopub.status.idle":"2022-11-22T02:37:49.843854Z","shell.execute_reply.started":"2022-11-22T02:37:45.288205Z","shell.execute_reply":"2022-11-22T02:37:49.842923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}