Encode targets to integers in [0, num_classes - 1]

def _encode_target(data, target, mapping=None):
    """ Encode targets to integers in [0, num_classes - 1] """
    if mapping is None:
        mapping = {t: i for i, t in enumerate(sorted(data[target].unique()))}

    data[target] = data[target].apply(lambda t: mapping[t])
    return data, mapping