{"cells":[{"metadata":{"_cell_guid":"f1e76927-fc2b-41f9-8da0-dc48c8897043","_uuid":"995a8c6b7ee9041fceaf3a601e993347f1fed583","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n%matplotlib inline\n         \nfrom keras.utils import np_utils\nfrom keras.models import Sequential\nfrom keras.layers import Dense\nfrom keras.optimizers import Adam\nfrom matplotlib.pyplot import imshow\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"7b5e3822-b973-428c-a165-dda564e61247","_uuid":"6543b3c156dc7a87133510767300ac83894af7cd","trusted":true},"cell_type":"code","source":"np.random.seed(1337)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"b181312e-af41-4452-8b3d-f9f75cc96479","_uuid":"d9feebde3f1ac7af92e8c75da5b0fb05db89a4ce","trusted":true},"cell_type":"code","source":"\ntrain = pd.read_csv(\"../input/train.csv\")\ntest= pd.read_csv(\"../input/test.csv\")\n","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"a9c613a0-cc2e-4263-bd94-e83625399502","_uuid":"934cdb400a5d82de5a8e47bb84600267d5c528f2","trusted":true},"cell_type":"code","source":"train.head(10)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"685c0651-c16d-4ae8-8d47-dbde82e819c2","_uuid":"26b21ec4035a2a542d9f96ba9f488b449211af2d","trusted":true},"cell_type":"code","source":"test.head(10)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"0d340e39-b05d-4627-9e37-9ca0026af173","_uuid":"ba80c88250c539b829fd64e69490a4da08c39612","trusted":true},"cell_type":"code","source":"train.groupby(['label'],axis=0).size()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"2cb30072-5ed8-432b-ac77-906ab2bf44a3","_uuid":"691ff203afd89d7ddd00e7f15c1e3fbe62d92bb9","trusted":true},"cell_type":"code","source":"X_train = train.drop(['label'],axis=1).astype('float32').values # all pixel values\ny_train = train['label'].astype('int32').values\nX_test = test.values.astype('float32')","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"7a5bdb7e-9aa0-47b3-93e0-cf27e0e85cdd","_uuid":"e3e2649be9acb14e68876ca3981e7f4a64bb2d95","trusted":true},"cell_type":"code","source":"X_train = X_train / 255\nX_train  = X_train.round()\nX_test = X_test / 255\nX_test  = X_test.round()\n\ny_train = np_utils.to_categorical(y_train)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"4c8559fd-8cdc-44b7-8161-9308406e32c5","_uuid":"068d6f39119533d84b70d2f87996dd16d644e7a4","trusted":true},"cell_type":"code","source":"pixelcount = X_train.shape[1]","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"860fcc85-e071-4382-84ac-0aa47ee75d1c","_uuid":"ae27806ee0a6744e38ef795bff4e41db82fb264d","trusted":true},"cell_type":"code","source":"model = Sequential()\nmodel.add(Dense(pixelcount, input_dim=pixelcount, kernel_initializer='normal', activation='relu'))\nmodel.add(Dense(10, kernel_initializer='normal', activation='softmax'))\n#Compile\nmodel.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"69055d8f-9602-4804-ae6a-120271d14962","_uuid":"e13cf7fa520e0cb6f66a1718fdabd4c3c02fbd79","scrolled":true,"trusted":true},"cell_type":"code","source":"model.fit(X_train, y_train,epochs=10, batch_size=200, verbose=2)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"cf2e1fa0-7785-4742-bd8e-a6ac175f7476","_uuid":"c26f8a34bd94970445de2b225d89f2dd292212b6","trusted":true},"cell_type":"code","source":"preds = model.predict(X_test)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"14fb4828-4ca1-4b21-9814-af2f61e0a253","_uuid":"4ccfb102673be01f55ab5fbe06eb4b38a401a2e4","trusted":true},"cell_type":"code","source":"test = np.argmax(preds,axis=1)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"d309bddf-66a0-4d88-9893-68ef94dafa48","_uuid":"32ae7b479299adc041d6280c02631e6fdd13c218","trusted":true},"cell_type":"code","source":"pd.DataFrame({\"ImageId\": list(range(1,len(test)+1)), \"Label\": test}).to_csv(\"mysubmit.csv\", index=False, header=True)","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}