def gini(event, nonevent):
    """Calculate the Gini coefficient given the number of events and
    non-events.

    Parameters
    ----------
    event : array-like
        Number of events.

    nonevent : array-like
        Number of non-events.

    Returns
    -------
    gini : float
    """
    event, nonevent = _check_x_y(event, nonevent)

    mask = (event + nonevent) > 0
    event = event[mask].astype(np.float64)
    nonevent = nonevent[mask].astype(np.float64)

    n = len(event)
    if n <= 1:
        return 0
    else:
        te = event.sum()
        tne = nonevent.sum()

        ner = nonevent / (event + nonevent)
        idx = np.argsort(ner)
        ev = event[idx]
        ne = nonevent[idx]

        s = np.zeros(n)
        s[1:] = 2.0 * ne[:-1].cumsum()

        return 1.0 - np.dot(ev, ne + s) / (te * tne)
Calculate the Gini coefficient given the number of events and
    non-events.

    Parameters
    ----------
    event : array-like
        Number of events.

    nonevent : array-like
        Number of non-events.

    Returns
    -------
    gini : float
    
optbinning/binning/metrics.py