def predict(clf, test_data, probabilities=True):
    """
    Returns an array of predictions for the given *test_data* using the classifier *clf*.
    If *probabilities* is True and the classifier supports it, the predictions will be Preictal probabilites.
    Otherwise, the class labels are used.

    :param clf: The classifier to use.
    :param test_data: The data to predict labels for.
    :param probabilities: If True and the classifier supports it, the array will contain class probabilites. Otherwise
                          it will contain 0-1 class guesses.
    :return: An ndarray with the class predictions for the test data.
    """
    if probabilities and hasattr(clf, 'predict_proba'):
        predictions = clf.predict_proba(test_data)
        # The predictions from predict_proba is a k-dimensional array, with k
        # the number of classes. We want to take the column corresponding to the
        # class with the label 1
        if hasattr(clf, 'best_estimator_'):
            classes = clf.best_estimator_.classes_
        else:
            classes = clf.classes_
        class_index = list(classes).index(1)
        predictions = predictions[:, class_index]
    else:
        predictions = clf.predict(test_data)
    return predictions