{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nfrom tensorflow import keras\nfrom keras import Sequential\nfrom tensorflow.keras.layers import Flatten, Dense\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### **Importing MNIST Dataset from keras**"},{"metadata":{"trusted":true},"cell_type":"code","source":"data = keras.datasets.mnist","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Splitting Data into training and testing."},{"metadata":{"trusted":true},"cell_type":"code","source":"(train_images, train_labels), (test_images, test_labels) = data.load_data()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_images.shape, train_labels.shape, test_images.shape, test_labels.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.imshow(train_images[0])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### **Data Preprocessing**\n\n*Normalizing Data*"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_images = train_images / 255.0\ntest_images  = test_images  / 255.0","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### **Building Model**"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = Sequential()\nmodel.add(Flatten(input_shape = (28,28)))\nmodel.add(Dense(128, activation = 'relu'))\nmodel.add(Dense(10 , activation = 'softmax'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.compile(\n                  optimizer = 'adam',\n                  loss      = 'sparse_categorical_crossentropy',\n                  metrics   = ['accuracy']\n             )","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.fit(train_images, train_labels, epochs = 10, validation_data = (test_images, test_labels))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"prediction = model.predict(test_images)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"prediction[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"np.argmax(prediction[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_labels[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(10,10))\nfor i in range(25):\n    plt.subplot(5,10,i+1)\n    plt.xticks([])\n    plt.yticks([])\n    plt.grid(False)\n    plt.imshow(test_images[i])\n    plt.title(test_labels[i])\n    plt.xlabel(np.argmax(prediction[i]))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}