import collections


def intermediate_node_num_mistakes(labels_in_node):
    """
    Purpose: Compute the number of mistakes in a decision tree node
             using majority classification
    Input  : Labels in the node
    Output : Number of mistakes
    """
    if len(labels_in_node) == 0:
        number_of_mistakes = 0
    else:
        class_counts = collections.Counter(labels_in_node)
        class_counts_positive = class_counts[1]
        class_counts_negative = class_counts[-1]
        if class_counts_positive >= class_counts_negative:
            number_of_mistakes = class_counts_negative
        else:
            number_of_mistakes = class_counts_positive
    return number_of_mistakes