text_plain_output_1.png
import numpy as np

import pandas as pd

import sklearn.preprocessing as pre

train_data = pd.read_csv('../input/train.csv')
test_data = pd.read_csv('../input/test.csv')
images = train_data.drop('label', 1)
observations, features = images.shape
pixel_width = int(np.sqrt(features))
X = images.as_matrix()
X_train = X.reshape(observations, pixel_width, pixel_width, 1)
print('Image Array', X_train.shape)
labels = train_data['label']
Y = labels.as_matrix()
labels = pre.LabelEncoder().fit_transform(labels)[:, None]
Y_train = pre.OneHotEncoder().fit_transform(labels).todense()
print('Label Array', Y_train.shape)
t = test_data.as_matrix()
tr, tc = t.shape
test = t.reshape(tr, pixel_width, pixel_width, 1)
print('Image Array', test.shape)