{"cells":[{"metadata":{"id":"eOnNN_CS5DLH","colab_type":"text","_uuid":"53e488d2519b621a43ee51920e8f0dba4f852303"},"cell_type":"markdown","source":" Reading the dataset from file will be first step in any data analytics project\n \nusually, the project files be in CSV file \"comma-seperated values\"\nLoad the data¶\n\n"},{"metadata":{"id":"RDHKA5rx6UQ6","colab_type":"code","colab":{},"trusted":true,"_uuid":"08173c2b785e253edffa9e3253e2d398fd0062a3"},"cell_type":"code","source":"import pandas as pd\n# create the training & test sets\ntrain = pd.read_csv(\"../input/train.csv\")\ntest= pd.read_csv(\"../input/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"id":"5aXUPVP4_qgJ","colab_type":"code","colab":{},"trusted":true,"_uuid":"dba79ba046d3eb06fab0fd7747310cb0ace5a5bd"},"cell_type":"code","source":"print(train.shape)\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{"id":"WRzbTy2yCsgF","colab_type":"code","colab":{},"trusted":true,"_uuid":"2a687a10dedf7eb8b0db301cf6f8d15e67ddf192"},"cell_type":"code","source":"print(test.shape)\ntest.head()","execution_count":null,"outputs":[]},{"metadata":{"id":"Hx025Hrf87QF","colab_type":"text","_uuid":"2bef26cf5181a848682abc63ea5ce70932ca529a"},"cell_type":"markdown","source":"Split Labels and images and convert data from pandas dataframe to numpy array"},{"metadata":{"id":"GUuOPj2j9EQY","colab_type":"code","colab":{},"trusted":true,"_uuid":"d406c419f31e1fbc2736d2313a4afdd703a70974"},"cell_type":"code","source":"X_train = train.drop(['label'], axis=1).values.astype('float32') / 255 # all pixel values\ny_train = train['label'].values.astype('int32') # only labels: targets digits\nX_test = test.values.astype('float32') / 255","execution_count":null,"outputs":[]},{"metadata":{"id":"SMBxzqGLC7zc","colab_type":"text","_uuid":"5da7f8039a7d9cee01cd8d4d16851be06740207f"},"cell_type":"markdown","source":"OR"},{"metadata":{"id":"wF8CPT9zC9g5","colab_type":"code","colab":{},"trusted":true,"_uuid":"80bb343cbebeb1ad4fe6b64dd5d46853015d4879"},"cell_type":"code","source":"x_train = (train.iloc[:,1:].values).astype('float32') / 255 # all pixel values\ny_train = train.iloc[:,0].values.astype('int32') # only labels i.e targets digits\nx_test = test.values.astype('float32') / 255\n","execution_count":null,"outputs":[]},{"metadata":{"id":"ipEhg9yH-LpQ","colab_type":"text","_uuid":"76e7d7060e91bb4a0833a4af51819cd6265801d5"},"cell_type":"markdown","source":"Change dimensions and expand 1 more dimension to store channels:\nCNN layers takes data shape as (num_images, img_rows, img_cols, n_channels)"},{"metadata":{"id":"cS6Npk1Y-HPY","colab_type":"code","colab":{},"trusted":false,"_uuid":"9e8b3a5468d0f9171df34933e003a4e3c39428f6"},"cell_type":"code","source":"X_train = X_train.reshape(X_train.shape[0], 28, 28,1)\nX_test = X_test.reshape(X_test.shape[0], 28, 28,1)","execution_count":null,"outputs":[]},{"metadata":{"id":"5xgox8R7-pRq","colab_type":"text","_uuid":"c234d1a2b18155d3f8f0064f1c1e56757a88db32"},"cell_type":"markdown","source":"Data preprocessing:\n1-One Hot encoding of labels:\nA one-hot vector is a vector which is 0 in most dimensions, and 1 in a single dimension.\nIn this case, the nth digit will be represented as a vector which is 1 in the nth dimension.\nFor example, 3 would be [0, 0, 0, 1, 0, 0, 0, 0, 0, 0].\n\n"},{"metadata":{"id":"y2oUoXEe_GEZ","colab_type":"code","colab":{},"trusted":true,"_uuid":"d8f324423dbf149875e586338dc093836464a54c"},"cell_type":"code","source":"from keras.utils.np_utils import to_categorical\ny_train = to_categorical(y_train)","execution_count":null,"outputs":[]},{"metadata":{"id":"BFAA7x7IDUt-","colab_type":"text","_uuid":"6a2b5e9bc8db9d8313e6a43074e84529ccca54d4"},"cell_type":"markdown","source":"OR"},{"metadata":{"id":"PJmWXCMFDWsd","colab_type":"code","colab":{},"trusted":true,"_uuid":"3f4f06cb83bb2a147993a0b565b8bd6bba7abe9f"},"cell_type":"code","source":"import keras\nnum_classes = 10\ny_train = keras.utils.to_categorical(y_train, num_classes)","execution_count":null,"outputs":[]}],"metadata":{"colab":{"name":"Pandas.ipynb","version":"0.3.2","provenance":[],"collapsed_sections":[]},"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}