{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train = pd.read_csv('../input/train.csv')\ntest = pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2eff1ea4fa81d935dee2868e3e0e4004f9af0f58"},"cell_type":"code","source":"print(train.shape, test.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f8f010bc5b27235d18f29fde6a65c41db7288cdb"},"cell_type":"code","source":"train_labels = train.iloc[:,0]\ntrain_images = train.iloc[:,1:]\n#test_labels = test.iloc[:,0]\ntest_images = test","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dc36f0471d1b68a8d3ddd380c20dc69df3aefb2e"},"cell_type":"code","source":"from keras import models, layers\n\nnetwork = models.Sequential()\nnetwork.add(layers.Dense(512, activation='relu', input_shape=(28*28, )))\n#network.add(layers.Dense(64, activation='relu'))\nnetwork.add(layers.Dense(10, activation='softmax'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ef8436d287c45e2df341bfd4e7aad8604ace941d"},"cell_type":"code","source":"network.compile(optimizer='rmsprop',\n               loss='categorical_crossentropy',\n               metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6b242cff8171d84155d8e884cc1482d6f4525b5e"},"cell_type":"code","source":"train_images = train_images.astype('float32')/255\ntest_images = test_images.astype('float32')/255","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d79afe8716b2ac65d7552a212c8f7e8f738d660a"},"cell_type":"code","source":"from keras.utils import to_categorical\n\ntrain_labels = to_categorical(train_labels)\n#test_labels = to_categorical(test_labels)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"48d3d025698552b5c698aaf387b794473dd41c38"},"cell_type":"code","source":"network.fit(train_images, train_labels, epochs=5, batch_size=128) #0.9871","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"188bb7df891ada436ee6e029575a06b2201745a1"},"cell_type":"code","source":"test_prediction = network.predict_classes(test_images)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"516a5e5592d9b7061a8f21ddb12ac0ce75b9aff8"},"cell_type":"code","source":"submission = pd.DataFrame(test_prediction).reset_index()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8ccae628d17468acd682e2ab791d6d1adf6faf71"},"cell_type":"code","source":"submission.columns=['ImageId','Label']\nsubmission['ImageId'] += 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d2a7c3575a13d57901a398ad37e50c9fcdc7f06"},"cell_type":"code","source":"submission.to_csv(\"submission.csv\",index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ce8835a36e2d481544f712e15c12eca08779e8a8"},"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}