<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Training the Classifier
The classification task is as follows
Step1:  The data has been saved to an hdf5 file.
Step2:  Keras is a high-level deep learning library.
Step3:  This model is relatively "shallow" as far as deep learning goes
<ASSISTANT_TASK:>
Python Code:
import porekit
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
import random
import h5py
from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder()
def transform_y(y):
    y = y.reshape(len(y),1)
    return enc.fit_transform(y).toarray()
def transform_x(x, mean, std):
    n,m = x.shape
    x.shape = (n, m, 1)
    x = (x-mean) / std
    return x
Explanation: Training the Classifier
The classification task is as follows: Given a sequence of 500 raw events, recognize the source genome.
Warning: This example is not yet polished to the point that it is easy to run. Patience please!
End of explanation
h5f = h5py.File('gclassify_11.h5', 'r')
training_X = h5f['training/X'][:]
mean, std = training_X.mean(), training_X.std()
training_X  = transform_x(training_X, mean, std)
training_y = transform_y(h5f['training/y'][:])
training_yc = h5f['training/y'][:]
validation_X = transform_x(h5f['validation/X'][:], mean, std)
validation_y = transform_y(h5f['validation/y'][:])
validation_yc = h5f['validation/y'][:]
h5f.close()
Explanation: The data has been saved to an hdf5 file.
End of explanation
from keras.models import Sequential
from keras.optimizers import SGD
from keras.layers.core import Dense, Activation, Dropout,  Flatten
from keras.layers.convolutional import Convolution1D, MaxPooling1D
from keras.regularizers import l2, activity_l2
Explanation: Keras is a high-level deep learning library.
End of explanation
model = Sequential()
model.add(Convolution1D(nb_filter=32,
                        filter_length=3,
                        border_mode='valid',
                        activation='relu',
                        subsample_length=1,
                        input_shape=(500,1),
                        #W_regularizer= l2(0.01),
                       ))
model.add(Dropout(0.2))
model.add(MaxPooling1D(pool_length=4))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(output_dim=100, init="glorot_uniform"))
model.add(Activation("relu"))
model.add(Dense(output_dim=3, init="glorot_uniform"))
model.add(Activation("softmax"))
model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.01, momentum=0.001, nesterov=True))
for i in range(120):
    model.fit(training_X, training_y, nb_epoch=1, batch_size=64)
    shuffle = np.random.choice(np.arange(len(training_X)), 1000, False)
    y = model.predict(training_X[shuffle])
    accuracy_training = np.sum(np.isclose(y.argmax(axis=1),training_yc[shuffle])) / len(y)
    y = model.predict(validation_X)
    accuracy_validation = np.sum(np.isclose(y.argmax(axis=1),validation_yc)) / len(y)
    print("%.2f %.2f" % (accuracy_training, accuracy_validation))
Explanation: This model is relatively "shallow" as far as deep learning goes:
End of explanation
<END_TASK>