{"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\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":"data = pd.read_csv('../input/train.csv')\ndata = np.array(data)\ndata","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"424b47a9c1b2aefa49b26c16158453356a89636f"},"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import MinMaxScaler\nscaler_Object = MinMaxScaler()\nX = data[:,1:]\ny = data[:,:1]\nX_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.33,random_state=42)\nX_train","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"243823e84a984374d46c5ec8bc351b6a37791e93"},"cell_type":"code","source":"y_train","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"183f1608d298b7a29db4a99e7a71086929f0941b"},"cell_type":"code","source":"scaler_Object.fit(X_train)\nscaled_X_train = scaler_Object.transform(X_train)\nscaled_X_test = scaler_Object.transform(X_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cd46c0c81ade4088ead02e395870fa893cd4bc54"},"cell_type":"code","source":"scaled_X_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5050c04bb36307e30aae6f26100e4aa80b35ff0a"},"cell_type":"code","source":"scaled_X_train.max()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a3c4dbe2a94707f35bf71e70ddf6fea7664c2c0a"},"cell_type":"code","source":"from keras.utils.np_utils import to_categorical\ny_cat_train = to_categorical(y_train,10)\ny_cat_test =  to_categorical(y_test,10)\ny_cat_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1477dabc4eb1a4ecca0ea714f1a757dc67656c47"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3ca6b58ff4a7c347c575cd201e7a9e38dc78d611"},"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6752d0a54e7878697245f3b118c4d20d6019705c"},"cell_type":"code","source":"model = Sequential()\nmodel.add(Dense(256,activation='relu',input_shape=(784,)))\nmodel.add(Dense(128,activation='relu'))\nmodel.add(Dense(10,activation='softmax'))\n\nmodel.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"747a9fdc188c514fb4ba88f5cbad135d2db5f0d9"},"cell_type":"code","source":"model.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"52369c8b3333c8857259c3ec9bb60f9ed6375768"},"cell_type":"code","source":"model.fit(scaled_X_train,y_cat_train,epochs=50,verbose=2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"242114e7e86a7328e4fbb6d6e5c4719f7c21a1fb"},"cell_type":"code","source":"from sklearn.metrics import confusion_matrix,classification_report\npredictions = model.predict_classes(scaled_X_test)\naccu = model.evaluate(scaled_X_test,y_cat_test)\npredictions","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ac09aea637a72b7495d70afd267d48941f73c3a3"},"cell_type":"code","source":"test_data = pd.read_csv('../input/test.csv')\ntest_data = np.array(test_data)\ntest_data","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"831a2d36a60168e89c2bb0de9d1dd11594edf319"},"cell_type":"code","source":"scaled_test_data = scaler_Object.transform(test_data)\nscaled_test_data","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"40bb31c21250e6940b7e18c9c8ca40edd0343880"},"cell_type":"code","source":"predictions_test_data = model.predict_classes(scaled_test_data)\npredictions_test_data","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"55cfa046d911cfdf2f3cc70a47d293c67e6a9c60"},"cell_type":"code","source":"data_to_submit = pd.DataFrame(columns=['Label'])\ndata_to_submit['Label'] = predictions_test_data\ndata_to_submit.insert(0, 'ImageID', range(1, 1 + len(data_to_submit)))\ndata_to_submit\ndata_to_submit.to_csv('csv_to_submit.csv', index = False)","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}