{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"import numpy as np\nimport pandas as pd\n\n%matplotlib inline\nimport matplotlib.pyplot as plt\nimport matplotlib.cm as cm\n\nimport tensorflow as tf\n\n# settings\nLEARNING_RATE = 1e-4\n# set to 20000 on local environment to get 0.99 accuracy\nTRAINING_ITERATIONS = 2500        \n    \nDROPOUT = 0.5\nBATCH_SIZE = 50\n\n# set to 0 to train on all available data\nVALIDATION_SIZE = 2000\n\n# image number to output\nIMAGE_TO_DISPLAY = 10"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"# read training data from CSV file \ndata = pd.read_csv('../input/train.csv')\n\nprint('data({0[0]},{0[1]})'.format(data.shape))\nprint (data.head())"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"images = data.iloc[:,1:].values\nimages = images.astype(np.float)\n\n# convert from [0:255] => [0.0:1.0]\nimages = np.multiply(images, 1.0 / 255.0)\nprint(images.shape)\nprint('images({0[0]},{0[1]})'.format(images.shape))"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"image_size = images.shape[1]\nprint ('image_size => {0}'.format(image_size))\n\n# in this case all images are square\nimage_width = image_height = np.ceil(np.sqrt(image_size)).astype(np.uint8)\n\nprint ('image_width => {0}\\nimage_height => {1}'.format(image_width,image_height))"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"# display image\ndef display(img):\n    \n    # (784) => (28,28)\n    one_image = img.reshape(image_width,image_height)\n    plt.axis('off')\n    plt.imshow(one_image, cmap=cm.binary)\n\n# output image     \n\ndisplay(images[IMAGE_TO_DISPLAY])"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"\nlabels_flat = data[[0]].values.ravel()\n\nprint('labels_flat({0})'.format(len(labels_flat)))\nprint ('labels_flat[{0}] => {1}'.format(IMAGE_TO_DISPLAY,labels_flat[IMAGE_TO_DISPLAY]))"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":false},"outputs":[],"source":"labels_count = np.unique(labels_flat).shape[0]\nprint(labels_count)\nprint('labels_count => {0}'.format(labels_count))"}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":0}