(y, sampling_type)
return sampling_strategy
Returns sampling target by targeting the majority class only.
Returns sampling target by targeting the majority class only.
Returns sampling target by targeting the majority class only .
def _sampling_strategy_majority(y, sampling_type):
    """Returns sampling target by targeting the majority class only."""
    if sampling_type == "over-sampling":
        raise ValueError(
            "'sampling_strategy'='majority' cannot be used with over-sampler."
        )
    elif sampling_type == "under-sampling" or sampling_type == "clean-sampling":
        target_stats = _count_class_sample(y)
        class_majority = max(target_stats, key=target_stats.get)
        n_sample_minority = min(target_stats.values())
        sampling_strategy = {
            key: n_sample_minority
            for key in target_stats.keys()
            if key == class_majority
        }
    else:
        raise NotImplementedError

    return sampling_strategy
def _sampling_strategy_majority ( y , sampling_type ) : if sampling_type == "over-sampling" : raise ValueError ( "'sampling_strategy'='majority' cannot be used with over-sampler." ) elif sampling_type == "under-sampling" or sampling_type == "clean-sampling" : target_stats = _count_class_sample ( y ) class_majority = max ( target_stats , key = target_stats . get ) n_sample_minority = min ( target_stats . values ( ) ) sampling_strategy = { key : n_sample_minority for key in target_stats . keys ( ) if key == class_majority } else : raise NotImplementedError return sampling_strategy