{"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)\nimport tensorflow as tf\nimport matplotlib.pyplot as plt\nfrom tensorflow import keras\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\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"# getting the data\ntraining_data = pd.read_csv('../input/train.csv')\ntest_data = pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3e844922547d12b8864db9ab02778ab56679a260"},"cell_type":"code","source":"# what does the data look like ?\ntest_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c00e2ec79c66a0cedc5f77afa974a96a918d92d4"},"cell_type":"code","source":"# spliting label and data\ntrain_label = training_data.label\ntrain_pixel = training_data.iloc[:,1:]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5655c1ea00cfd1969af6f9dae1d4d630702826f7"},"cell_type":"code","source":"#let's try to visualize an image\nplt.imshow(train_pixel.iloc[3,:].values.reshape(28,28))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"649b6e7d398f0ff28f38f0309b56719f18397a80"},"cell_type":"code","source":"# preprocess the data\ntrain_pixel /= 255.0\ntest_data /= 255.0","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e79e09a4a1a207aecaced09b1593d3aaf7e5d64e"},"cell_type":"code","source":"# model - simple classification\nmodel = keras.Sequential([\n    keras.layers.Dense(128, activation=tf.nn.relu),\n    keras.layers.Dense(10, activation=tf.nn.softmax)\n])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d0b8f08ffea31dca9e1cf3f15ef0c506505be578"},"cell_type":"code","source":"model.compile(optimizer=tf.train.AdamOptimizer(), \n              loss='sparse_categorical_crossentropy',\n              metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"ea01f6ccd472285b15479f8e1eac54678959f5f8"},"cell_type":"code","source":"# and we can start training it\nmodel.fit(train_pixel.values, train_label.values, epochs=10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"641e31ee48e5eeac6665264f486da7e2151afcea"},"cell_type":"code","source":"predictions = model.predict(test_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"731f12f2367e28995a141c5cdd78f38a1dd5cd54"},"cell_type":"code","source":"type(predictions)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dd65039ee7e788487a3510d9f033e67b0208238e"},"cell_type":"code","source":"predic = np.argmax(predictions,axis=1)\nImageId = test_data.index + 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"79cac1ede48ab2a1fd4254a95bae4ea4309ad4a5"},"cell_type":"code","source":"my_submission = pd.DataFrame({'ImageId': ImageId, 'Label': predic})\nmy_submission.to_csv('submission.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"33383f622eae28b7fdd0aa9a271bcd3df7b4fa91"},"cell_type":"code","source":"","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}