def test_cost_function(train_data, test_data):
    x, y, y_onehot, = train_data
    x_test, y_test = test_data
    network = NeuralNetwork(layers=[784, 25, 10])
    network.fit(x, y_onehot, alpha=0.1, iterations=40)
    prediction_test = network.predict(x_test)
    accuracy_test = accuracy(prediction_test, y_test)
    assert accuracy_test > 90
示例#2
0
if __name__ == '__main__':
    # Reading data, Inintializing classes in the workspace
    hlp, ft, als = Helpers(), Features(), Analysis()
    all_data = hlp.saveReadToLocal('read', '_all_av45', None, '_cache')
    all_data = all_data['av45']
    keys = ['normal', 'mci', 'ad', 'labels_normal', 'labels_mci', 'labels_ad']

    mixed_all_data = als.getTrainingSet(all_data, 0, 0, keys, do_split=False)
    print('Features dimention before normalization: ',
          len(mixed_all_data[0][0]))
    mixed_all_data = ft.normalizeFeatures(mixed_all_data)
    print('Features dimention after normalization: ', len(mixed_all_data[0][0]))
    # mixed_all_data = als._cleanDataset(mixed_all_data[0],  mixed_all_data[1])

    # grid_params = runAnalysis(mixed_all_data, classifier='svm')
    # a = runAnalysis(mixed_all_data, params=grid_params, classifier='svm')
    # print('Overall accuracy: ', np.mean(a))

    input_size = len(mixed_all_data[0][0])
    nn = NeuralNetwork([input_size, input_size, 40, 40, 3])
    input_data = np.asarray(mixed_all_data[0]).reshape(
        (input_size, len(mixed_all_data[0])))
    input_labels = np.asarray(mixed_all_data[1]).reshape(
        (1, len(mixed_all_data[1])))
    nn.run(input_data, input_labels, 0.01, 5000)

    test = np.asarray(mixed_all_data[0][0]).reshape(
        (input_size, 1))
    print(nn.predict(test))