{"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\n#print(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":"raw = pd.read_csv(\"../input/train.csv\", sep=',')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9b927161f7a315e0e39479a6cba844fc85db6f18"},"cell_type":"code","source":"trainLabels = raw['label']\ntrainInputs = raw.drop(columns = ['label'], axis=1).values/255","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fe98f4a225810dfc7e81e3314e319a3a9dcd759c"},"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"daa2853a71682d904e8b73595fba60c5db4c618a"},"cell_type":"code","source":"with tf.Session():\n    trainLabels = tf.one_hot(trainLabels.astype('int32'), 10).eval()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d9c94feaf59ce2394ae5d006fb7410e794f8cff5"},"cell_type":"code","source":"model = keras.Sequential([\n    keras.layers.Dense(128, activation=tf.nn.relu),\n    keras.layers.Dense(64, activation=tf.nn.tanh),\n    keras.layers.Dense(32, activation=tf.nn.relu),\n    keras.layers.Dense(10, activation=tf.nn.softmax)\n])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c4e329f25b2273ff68b61c5017f749de84ef1fe3"},"cell_type":"code","source":"model.compile(optimizer=tf.train.AdamOptimizer(),\n              loss='categorical_crossentropy')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bf6214848976252db70bfb866533c2301b723951"},"cell_type":"code","source":"model.fit(trainInputs, trainLabels, epochs=10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3f808da95adb4403affe8dcf7821ab313ab717a8"},"cell_type":"code","source":"test = pd.read_csv(\"../input/test.csv\", sep=',')\ntest = test.values/255","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3eabe8d693a07266c28c7e8b9d8336f5e7de8c8f"},"cell_type":"code","source":"output = model.predict(test)\noutput = np.argmax(output, axis = 1)\noutput = pd.DataFrame({'ImageId' : np.arange(1,len(output)+1), 'label' : output})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c0ad18fea9804ab0d4f2b5cd60fb18feee315da2"},"cell_type":"code","source":"output.to_csv(\"submission2.csv\", index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"087b19092455e168cd50674503c444f6b992bf70"},"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}