def imbalance_metrics(data):
    """ Computes imbalance metric for a given dataset. 
    Imbalance metric is equal to 0 when a dataset is perfectly balanced (i.e. number of in each class is exact).
    :param data : pandas.DataFrame 
        A dataset in a panda's data frame
    :returns int 
        A value of imbalance metric, where zero means that the dataset is perfectly balanced and the higher the value, the more imbalanced the dataset.
    """
    if not data:
        return 0
    #imb - shows measure of inbalance within a dataset
    imb = 0 
    num_classes=float(len(Counter(data)))
    for x in Counter(data).values():
        p_x = float(x)/len(data)
        if p_x > 0:
            imb += (p_x - 1/num_classes)*(p_x - 1/num_classes)
    #worst case scenario: all but 1 examplars in 1st class, the remaining one in 2nd class
    worst_case=(num_classes-1)*pow(1/num_classes,2) + pow(1-1/num_classes,2)
    return (num_classes,imb/worst_case)
Computes imbalance metric for a given dataset. 
    Imbalance metric is equal to 0 when a dataset is perfectly balanced (i.e. number of in each class is exact).
    :param data : pandas.DataFrame 
        A dataset in a panda's data frame
    :returns int 
        A value of imbalance metric, where zero means that the dataset is perfectly balanced and the higher the value, the more imbalanced the dataset.