<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Ok, we've had a little peek at our dataset, lets prep it for our model.
Step1:  Prep is done, time for the model.
Step2:  We've defined the cost and accuracy functions, time to train our model.
<ASSISTANT_TASK:>
Python Code:
randinds = np.random.permutation(len(digits.target))
# shuffle the values
from sklearn.utils import shuffle
data, targets = shuffle(digits.data, digits.target, random_state=0)
# scale the data
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler().fit(data)
data_scaled = scaler.transform(data)
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(data_scaled, targets, test_size=0.20, random_state=0)
X_train.shape, y_train.shape
Explanation: Ok, we've had a little peek at our dataset, lets prep it for our model.
End of explanation
from cgt.distributions import categorical
def model(X, y):
    # relu(W*x + b)
    np.random.seed(0)
    h1 = nn.rectify(nn.Affine(64, 512, weight_init=nn.IIDGaussian(std=.1))(X))
    h2 = nn.rectify(nn.Affine(512, 512, weight_init=nn.IIDGaussian(std=.1))(h1))
    # softmax probabilities
    probs = nn.softmax(nn.Affine(512, 10)(h2))
    
    # our prediction is the highest probability
    ypreds = cgt.argmax(probs, axis=1)
        
    acc = cgt.cast(cgt.equal(ypreds, y), cgt.floatX).mean()
    cost = -categorical.loglik(y, probs).mean()
    
    return cost, acc
X = cgt.matrix(name='X', fixed_shape=(None, 64))
y = cgt.vector(name='y', dtype='i8')
cost, acc = model(X, y)
Explanation: Prep is done, time for the model.
End of explanation
learning_rate = 1e-3
epochs = 100
batch_size = 64
# get all the weight parameters for our model
params = nn.get_parameters(cost)
# train via SGD, use 1e-3 as the learning rate
updates = nn.sgd(cost, params, learning_rate)
# Functions
trainf = cgt.function(inputs=[X,y], outputs=[], updates=updates)
cost_and_accf = cgt.function(inputs=[X,y], outputs=[cost,acc])
import time
for i in xrange(epochs):
    t1 = time.time()
    for srt in xrange(0, X_train.shape[0], batch_size):
        end = batch_size+srt
        trainf(X_train[srt:end], y_train[srt:end])
    elapsed = time.time() - t1
    costval, accval = cost_and_accf(X_test, y_test)
    print("Epoch {} took {}, test cost = {}, test accuracy = {}".format(i+1, elapsed, costval, accval))
    
Explanation: We've defined the cost and accuracy functions, time to train our model.
End of explanation
<END_TASK>