def obtainKaggleTestResults(Theta1, Theta2):
    ''' Apply the learned neural network paramaters to predict the
        results on the Kaggle Test Data.
    '''

    # get the data to do the final test.
    m, n, X = getKaggleTestData()

    # Select some random images from X
    print('Selecting random examples of the test data to display.\n')
    sel = np.random.permutation(m)
    sel = sel[0:100]
    images = X[sel, :]

    # display the sample images
    displayData(images)

    # predict the labels
    pred = predict(Theta1, Theta2, X)

    # print out what the images are predicted to be
    print('Here are the predicted labels for these random images: \n')
    print(pred[sel].reshape(10, 10))

    # Pause
    print("Program paused. Press Ctrl-D to continue.\n")
    code.interact(local=dict(globals(), **locals()))
    print(" ... continuing\n ")

    return pred
def displaySampleData(X, y):
    ''' Display random images as a grid, along with the corresponding labels'''
    m, n = X.shape
    # Select some random images from X
    print('Selecting random examples of the data to display.\n')
    sel = np.random.permutation(m)
    sel = sel[0:100]
    images = X[sel, :]

    # display the sample images
    displayData(images)

    # Print Out the labels for what is being seen. 
    print('These are the labels for the data ...\n')
    print(y[sel, :].reshape(10, 10))
예제 #3
0
def visualizeNN(Theta, hidden_layer_size, iters, _lambda):
    """ Visualize NN Weights that have been learned.

        You can now "visualize" what the neural network is learning by 
        displaying the hidden units to see what features they are capturing in 
        the data.
    """

    print ("\nVisualizing Trained Neural Network... \n")
    print (
        "\n  Parms: Hidden Layer Units: {0}  Max Iters: {1}  Lambda: {2}  \n".format(hidden_layer_size, iters, _lambda)
    )

    displayData(Theta[:, 1:])

    # Pause
    print ("Program paused. Press Ctrl-D to continue.\n")
    code.interact(local=dict(globals(), **locals()))
    print (" ... continuing\n ")

    return
    test = pd.read_csv(fnTest)

    M = test.as_matrix() # gives numpy array
    X = M[:,0:]    # The test data

    # Scale the input grey scale pixels by 255 to between -1 to 1 if scale by 1
    #   
    X = X.astype('float')
    X = (X - ( X.max() /float(scale)))/X.max()
 
    # Find number of rows examples "m", & columns features "n" 
    m, n = X.shape 

    return m, n, X   

'''
# old matlab code below
% There is no label y,so comment out this part. 
%  y = X(:, 1);
%  Replace the 0's with 10 in y for indexing purposes
%  y(y==0) = 10;
% X = X(:, 2:end);

m = size(TEST, 1);

% Re-orient the images
for i = 1: m 
    TEST(i, :) = reshape(reshape(TEST(i, :), ... 
        image_size, image_size)', ...
        1, input_layer_size);
end