{"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# importing the keras libraries and packages\nfrom keras.layers import Dense\nfrom keras.models import Sequential\nfrom tensorflow import keras\nimport tensorflow as tf\n# Helper libraries\nimport matplotlib.pyplot as plt\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":"train_data=pd.read_csv('../input/train.csv')\ntest_data=pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c0108e3949ce7c189bcdeb81a394b8eea840d12a"},"cell_type":"code","source":"# preprocessing the data\ndef get_features_labels(df):\n    features=df.values[:,1:]/255\n    labels=df['label'].values\n    return features, labels","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"90311307c915bcbc69cc05f119471a50c832ffdc"},"cell_type":"code","source":"train_features, train_labels= get_features_labels(train_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e549e738ad2c994811ddd09df0cfc0f56b8bc7ea"},"cell_type":"code","source":"test_features= test_data.values[:,0:]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"67f448f8abd66783202e136a96b89c8272026d19"},"cell_type":"code","source":"# convert labels to one hot encoding\ntrain_labels=tf.keras.utils.to_categorical(train_labels)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f12dbb566784b34232c0258fceccff087cf00d11"},"cell_type":"code","source":"train_features.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3b06f1bcd335da28d1382e9fb4614f308f6d31ef"},"cell_type":"code","source":"#initialize ANN\nclassifier=Sequential()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a651ae5799f75be2619cbb0034314401b81c2547"},"cell_type":"code","source":"# hidden layers\nclassifier.add(Dense(units=397,activation='relu', kernel_initializer='uniform',input_shape=(784,)))\nclassifier.add(Dense(units=397,kernel_initializer='uniform', activation='relu'))\nclassifier.add(Dense(units=397,kernel_initializer='uniform', activation='relu'))\nclassifier.add(Dense(units=397,kernel_initializer='uniform', activation='relu'))\nclassifier.add(Dense(units=397,kernel_initializer='uniform', activation='relu'))\n# output layer\nclassifier.add(Dense(units=10, kernel_initializer='uniform',activation='softmax'))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5494cdb08fa5dc17ae52e369df0fe63bf466a9cb"},"cell_type":"code","source":"# compiling ANN\nclassifier.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d0afb604fedf943ffb69b9215c179bc321410eb2"},"cell_type":"code","source":"# fitting the ANN to the training set\nEPOCHS=4\nBATCH_SIZE=150\nclassifier.fit(train_features,train_labels,batch_size=BATCH_SIZE,epochs=EPOCHS)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"06f2c50870efae7f6e3681cf049823ff58721c41"},"cell_type":"code","source":"predictions=classifier.predict(test_features)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4192c0ab92fec7df5157fd23f10edc65f436392f"},"cell_type":"code","source":"np.argmax(predictions[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"11022fbb2ec8e052e4fcfc39c8e18cf9ce7a5d0d"},"cell_type":"code","source":"class_names=[0,1,2,3,4,5,6,7,8,9]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1d26bc61396e0a15972b13ae0b76a3bb80dde731"},"cell_type":"code","source":"plt.figure(figsize=(10,10))\nfor i in range(100):\n    pred_label = np.argmax(predictions[i])\n    pred_name = class_names[pred_label]\n    test_array_data=np.reshape(test_data[test_data.columns[0:]].iloc[i].values,(28,28))\n    plt.subplot(10,10,i+1)\n    plt.title(pred_name)\n    plt.imshow(test_array_data,'gray')\nplt.tight_layout() ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f28dbd1e355f9f5b06d5a07f93ffb90e281f7ec8"},"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}