core/src/autogluon/core/utils/utils.py
def augment_rare_classes(X, label, threshold):
    """ Use this method when using certain eval_metrics like log_loss, for which no classes may be filtered out.
        This method will augment dataset with additional examples of rare classes.
    """
    class_counts = X[label].value_counts()
    class_counts_invalid = class_counts[class_counts < threshold]
    if len(class_counts_invalid) == 0:
        logger.debug("augment_rare_classes did not need to duplicate any data from rare classes")
        return X

    missing_classes = []
    for clss, n_clss in class_counts_invalid.iteritems():
        if n_clss == 0:
            missing_classes.append(clss)
    if missing_classes:
        logger.warning(f'WARNING: Classes were found that have 0 training examples, and may lead to downstream issues. '
                       f'Consider either providing data for these classes or removing them from the class categories. '
                       f'These classes will be ignored: {missing_classes}')
        class_counts_invalid = class_counts_invalid[~class_counts_invalid.index.isin(set(missing_classes))]

    aug_df = None
    for clss, n_clss in class_counts_invalid.iteritems():
        n_toadd = threshold - n_clss
        clss_df = X.loc[X[label] == clss]
        if aug_df is None:
            aug_df = clss_df[:0].copy()
        duplicate_times = int(np.floor(n_toadd / n_clss))
        remainder = n_toadd % n_clss
        new_df = clss_df.copy()
        new_df = new_df[:remainder]
        while duplicate_times > 0:
            logger.debug(f"Duplicating data from rare class: {clss}")
            duplicate_times -= 1
            new_df = new_df.append(clss_df.copy())
        aug_df = aug_df.append(new_df.copy())

    X = X.append(aug_df)
    class_counts = X[label].value_counts()
    class_counts_invalid = class_counts[class_counts < threshold]
    class_counts_invalid = class_counts_invalid[~class_counts_invalid.index.isin(set(missing_classes))]
    if len(class_counts_invalid) > 0:
        raise RuntimeError("augment_rare_classes failed to produce enough data from rare classes")
    logger.log(15, "Replicated some data from rare classes in training set because eval_metric requires all classes")
    return X
 Use this method when using certain eval_metrics like log_loss, for which no classes may be filtered out.
        This method will augment dataset with additional examples of rare classes.
    
Use this method when using certain eval_metrics like log_loss, for which no classes may be filtered out.
This method will augment dataset with additional examples of rare classes.
Use this method when using certain eval_metrics like log_loss for which no classes may be filtered out . This method will augment dataset with additional examples of rare classes .
def augment_rare_classes(X, label, threshold):
    class_counts = X[label].value_counts()
    class_counts_invalid = class_counts[class_counts < threshold]
    if len(class_counts_invalid) == 0:
        logger.debug("augment_rare_classes did not need to duplicate any data from rare classes")
        return X
    missing_classes = []
    for clss, n_clss in class_counts_invalid.iteritems():
        if n_clss == 0:
            missing_classes.append(clss)
    if missing_classes:
        logger.warning(f'WARNING: Classes were found that have 0 training examples, and may lead to downstream issues. '
                       f'Consider either providing data for these classes or removing them from the class categories. '
                       f'These classes will be ignored: {missing_classes}')
        class_counts_invalid = class_counts_invalid[~class_counts_invalid.index.isin(set(missing_classes))]
    aug_df = None
    for clss, n_clss in class_counts_invalid.iteritems():
        n_toadd = threshold - n_clss
        clss_df = X.loc[X[label] == clss]
        if aug_df is None:
            aug_df = clss_df[:0].copy()
        duplicate_times = int(np.floor(n_toadd / n_clss))
        remainder = n_toadd % n_clss
        new_df = clss_df.copy()
        new_df = new_df[:remainder]
        while duplicate_times > 0:
            logger.debug(f"Duplicating data from rare class: {clss}")
            duplicate_times -= 1
            new_df = new_df.append(clss_df.copy())
        aug_df = aug_df.append(new_df.copy())
    X = X.append(aug_df)
    class_counts = X[label].value_counts()
    class_counts_invalid = class_counts[class_counts < threshold]
    class_counts_invalid = class_counts_invalid[~class_counts_invalid.index.isin(set(missing_classes))]
    if len(class_counts_invalid) > 0:
        raise RuntimeError("augment_rare_classes failed to produce enough data from rare classes")
    logger.log(15, "Replicated some data from rare classes in training set because eval_metric requires all classes")
    return X
def augment_rare_classes ( X , label , threshold ) : class_counts = X [ label ] . value_counts ( ) class_counts_invalid = class_counts [ class_counts < threshold ] if len ( class_counts_invalid ) == 0 : logger . debug ( "augment_rare_classes did not need to duplicate any data from rare classes" ) return X missing_classes = [ ] for clss , n_clss in class_counts_invalid . iteritems ( ) : if n_clss == 0 : missing_classes . append ( clss ) if missing_classes : logger . warning ( f'WARNING: Classes were found that have 0 training examples, and may lead to downstream issues. ' f'Consider either providing data for these classes or removing them from the class categories. ' f'These classes will be ignored: {missing_classes}' ) class_counts_invalid = class_counts_invalid [ ~ class_counts_invalid . index . isin ( set ( missing_classes ) ) ] aug_df = None for clss , n_clss in class_counts_invalid . iteritems ( ) : n_toadd = threshold - n_clss clss_df = X . loc [ X [ label ] == clss ] if aug_df is None : aug_df = clss_df [ : 0 ] . copy ( ) duplicate_times = int ( np . floor ( n_toadd / n_clss ) ) remainder = n_toadd % n_clss new_df = clss_df . copy ( ) new_df = new_df [ : remainder ] while duplicate_times > 0 : logger . debug ( f"Duplicating data from rare class: {clss}" ) duplicate_times -= 1 new_df = new_df . append ( clss_df . copy ( ) ) aug_df = aug_df . append ( new_df . copy ( ) ) X = X . append ( aug_df ) class_counts = X [ label ] . value_counts ( ) class_counts_invalid = class_counts [ class_counts < threshold ] class_counts_invalid = class_counts_invalid [ ~ class_counts_invalid . index . isin ( set ( missing_classes ) ) ] if len ( class_counts_invalid ) > 0 : raise RuntimeError ( "augment_rare_classes failed to produce enough data from rare classes" ) logger . log ( 15 , "Replicated some data from rare classes in training set because eval_metric requires all classes" ) return X
Use this method when using certain eval_metrics like log_loss, for which no classes may be filtered out.
Use this method when using certain eval_metrics like log_loss for which no classes may be filtered out .
""" Use this method when using certain eval_metrics like log_loss, for which no classes may be filtered out.
        This method will augment dataset with additional examples of rare classes.
    """
X
label
threshold