text_plain_output_2.png text_plain_output_1.png
from IPython import display

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import OneHotEncoder

def history_plot(fit_history):
    keys = list(fit_history.history.keys())[0:4]
def ohe(x):
    return OneHotEncoder(categories='auto').fit(x.reshape(-1, 1)).transform(x.reshape(-1, 1)).toarray().astype('int64')
def tts(X, y):
    x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)
    n = int(len(x_test) / 2)
    x_valid, y_valid = (x_test[:n], y_test[:n])
    x_test, y_test = (x_test[n:], y_test[n:])
    return (x_train, x_valid, x_test, y_train, y_valid, y_test)

f = h5py.File('../input/LetterColorImages_123.h5', 'r')
keys = list(f.keys())
keys

letters = u'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
backgrounds = np.array(f[keys[0]])
labels = np.array(f[keys[2]])
images = np.array(f[keys[1]]) / 255

gray_images = np.dot(images[..., :3], [0.299, 0.587, 0.114])
rn = np.random.randint(10000)
pl.xticks([])
pl.yticks([])
gray_images = gray_images.reshape(-1, 32, 32, 1)

cbackgrounds, clabels = (ohe(backgrounds), ohe(labels))
ctargets = np.concatenate((clabels, cbackgrounds), axis=1)
display.display(pd.DataFrame([labels[97:103], clabels[97:103]]).T)
pd.DataFrame([clabels.shape, cbackgrounds.shape, ctargets.shape])