def gini(sub_set):
    """Calculate the gini impurity."""
    sub_set_len = len(sub_set)
    good = 0
    for set_row in sub_set:
        if set_row[-1] > 6:
            good = good + 1
    gini_impurity = 1 - (good / sub_set_len) ** 2 - ((sub_set_len - good) / sub_set_len) ** 2
    return gini_impurity