{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.\n#https://pythonprogramming.net/introduction-deep-learning-python-tensorflow-keras/","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import tensorflow.keras as keras #importing deep learning library\nimport tensorflow as tf #deep learning library\nprint(tf.__version__)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5bce28dff88fae44406a9fa6dbd97bfe8c6ef78b"},"cell_type":"code","source":"mnist = tf.keras.datasets.mnist\n(x_train, y_train),(x_test, y_test) = mnist.load_data()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9ae04ef7301ebb3f9bd3085198e8e6eb72fd32aa"},"cell_type":"code","source":"import pandas as pd\ndf = pd.read_csv('../input/train.csv')\ndf.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0d88a421da22c52092152d7f823f031430cc9114"},"cell_type":"code","source":"df.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"04c8e4fb61f02644cac0746ada6cfba59538e14a"},"cell_type":"code","source":"print(df.values[0])\n# print(x_train[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"52861b4684bae47d9831f10eae025c1b2f625598"},"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.imshow(x_train[0],cmap=plt.cm.binary)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"558a4cb12297a110c244647e9c1e4d62ddc1d060"},"cell_type":"code","source":"# x_train = tf.keras.utils.normalize(x_train, axis=1)\n# x_test = tf.keras.utils.normalize(x_test, axis=1)\ny_train_2 = df['label']\ndf = df / 255\nimport numpy as np\nlabels = df.columns.tolist()\nlabels.remove('label')\ndf = df[labels]\ndf.head()\nx_train_2 = df\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0933909e1351ae39b9407972fca31e1a03146ea2"},"cell_type":"code","source":"# x_train_2.values[0]\ny_train_2.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4a807c2867aff89ddbd9ca2bf51c3cb81cf5176b"},"cell_type":"code","source":"model = tf.keras.models.Sequential()\nmodel.add(tf.keras.layers.Flatten())\nmodel.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))\nmodel.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))\nmodel.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax))\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"56b8253b17c3b74845ef2939b19c7c28b844df53"},"cell_type":"code","source":"model.compile(optimizer='adam',\n              loss='sparse_categorical_crossentropy',\n              metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"854f98a2662ac7f582904434662f1cf81300afad"},"cell_type":"code","source":"# model.fit(x_train, y_train, epochs=3)\nmodel.fit(x_train_2.values, y_train_2.values, epochs=3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a96323801c532af175d3a4be4338b9c786475efe"},"cell_type":"code","source":"# model.save('epic_num_reader.model')\n# new_model = tf.keras.models.load_model('epic_num_reader.model')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d37d8caa3a6e2897f043c012b1b1d574dda8362"},"cell_type":"code","source":"predictions = model.predict(x_test)\nimport numpy as np\n\nprint(np.argmax(predictions[5]))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ee6a86d9ec91d02d27c7392aa8fe83118147a47b"},"cell_type":"code","source":"plt.imshow(x_test[5],cmap=plt.cm.binary)\nplt.show()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}