{"cells":[{"metadata":{"_cell_guid":"b8c36e86-5bf2-4a6c-9be6-1da3252db327","_uuid":"260de30deea9102e67e143172d8e643e2b9ad682","trusted":false},"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\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"33810f9a0644fe2de66f4027f68ab014bf296c3d","trusted":false},"cell_type":"code","source":"train = pd.read_csv(\"../input/train.csv\")\ntest = pd.read_csv(\"../input/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4cb27d4e2742853c4338be2e888322a314605bbb","trusted":false},"cell_type":"code","source":"print(train.shape)\nprint(test.shape)","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"808a2172652c4e7864e8113615bc0324326f2544","trusted":false},"cell_type":"code","source":"x_train = train.drop(labels= [\"label\"],axis = 1)","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"73619cf2e16dbcbddc03f8531343d74c4208fcdd","trusted":false},"cell_type":"code","source":"y_train = train[\"label\"]","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"1020c5bd384b7d88a690353707b91d0e6f391081","trusted":false},"cell_type":"code","source":"y_train","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3acc663469e73ffd4db88f8371382dacde4f0a4c","trusted":false},"cell_type":"code","source":"x_train","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"bc989282297ae0cf41f17a4d8495aad253d912d9","trusted":false},"cell_type":"code","source":"import keras","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"eec9fa95aa968df5dc4ded317720b3790c74fb4b","trusted":false},"cell_type":"code","source":"import numpy as np","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"d5322cd915c56185b313d7368799c1ffbbcd7484","trusted":false},"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Activation, Flatten, Add\nfrom keras.layers import Convolution2D, MaxPooling2D\nfrom keras.utils import np_utils","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a69263d8999719748b85c4cb49f28be5da0e6f21","trusted":false},"cell_type":"code","source":"%matplotlib inline\nimport matplotlib.pyplot as plt\ng = plt.imshow(x_train[0][:,:,0])","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3a21ebf7acaff00b93926859016fbf49fffd8a97","trusted":false},"cell_type":"code","source":"x_train = x_train.values.reshape(-1,28,28,1)\ntest = test.values.reshape(-1,28,28,1)","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"5baf1ea5608d9127e7b7109222dabeb8c49d2c53","trusted":false},"cell_type":"code","source":"x_train = x_train.astype('float32')\ntest = test.astype('float32')","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"3c40a5f5d26f4cfd7abbba327e01bcb4cc5de68c","trusted":false},"cell_type":"code","source":"x_train /=255\ntest /=255","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"485283714a58bab1a0ce539f8de5618ce2395956","trusted":false},"cell_type":"code","source":"y_train[:10]","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9f29187397c4d7f5cb735af0661edee328db61d0","trusted":false},"cell_type":"code","source":"y_train = np_utils.to_categorical(y_train, 10)\ntest = np_utils.to_categorical(test, 10)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ebc17e26b9617f504294717e33d832a2d75a20ff","trusted":false},"cell_type":"code","source":"y_train[:10]","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e73a3047c35afd03d712337567695fef290ba5c9","trusted":false},"cell_type":"code","source":"model = Sequential()\nmodel.add(Convolution2D(32,3,3, activation='relu', input_shape=(28,28,1)))\nmodel.add(Convolution2D(32,3,3, activation='relu'))\n\nmodel.add(MaxPooling2D(pool_size=(2,2)))\nmodel.add(Dropout(0.25))\n\nmodel.add(Flatten())\nmodel.add(Dense(128, activation='relu'))\nmodel.add(Dropout(0.50))\nmodel.add(Dense(10, activation='softmax'))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"45f1e7faa24b77c0f2d254cb6a2672907b929dec","trusted":false},"cell_type":"code","source":"model.summary()","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"2524177d73cc04608114e1263e580480bc6dedeb","trusted":false},"cell_type":"code","source":"model.compile(loss ='categorical_crossentropy',optimizer = 'adam',metrics =['accuracy'])\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"186091c302baf68358e7ede03c76ecadb43ef25b","trusted":false},"cell_type":"code","source":"model.fit(x_train, y_train, batch_size=32, nb_epoch=3, verbose = 1)","execution_count":null,"outputs":[]},{"metadata":{"collapsed":true,"_uuid":"1bcd2038ab4fcbf0507ea4e6978f70732e92175c","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"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"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":1}