def gini(labels):
    """
    Calculate the Gini value of the data set
    :param labels: Category label for the dataset
    :return gini_value: The Gini value of the data set
    """

    data_count = {}
    for label in labels:
        if data_count.__contains__(label):
            data_count[label] += 1
        else:
            data_count[label] = 1

    n = len(labels)
    if n == 0:
        return 0

    gini_value = 1
    for key, value in data_count.items():
        gini_value -= (value / n) ** 2

    return gini_value