def test_classifier(classifier, test_data, test_labels=None):
    """ test_classifier function

    Tests a given classifier on the given test data and outputs the results.
    If test_labels is given, will calculate and print accuracy.

    Args
    ----
    classifier : LogisticRegression
        classifier to be tested
    test_data : np.array
        matrix of size N x p where N is the number of data points and p
        is the number of features
    test_labels : np.array (default None)
        the list of labels for the associated data set

    Returns
    -------
    LogisticRegression
    """
    guesses = classifier.predict(test_data)

    if test_labels is not None:
        right = 0.0
        total = 0.0
        for i in range(len(guesses)):
            guess = guesses[i]
            actual = test_labels[i]
            if guess == actual:
                right += 1.0
            total += 1.0
        print("Accuracy: " + str(right/total))
    return guesses