prep/preprocessor.py
def balance_class_sizes(X, y):
    """
    Balance classes for binary classification. Perform in-place manipulation of array.
    :param X: list of feature vectors
    :param y: class labels (0 and 1)
    """
    with LogCont("Subsample majority class"):
        indices_of_classes = get_indices_of_classes(X, y)
        cl0 = indices_of_classes[0]
        if len(indices_of_classes) > 1:
            cl1 = indices_of_classes[1]
        else:
            cl1 = []
        if len(cl0) > len(cl1):
            len_maj = len(cl0)
            len_min = len(cl1)
            cl_maj = cl0
        else:
            len_maj = len(cl1)
            len_min = len(cl0)
            cl_maj = cl1
        if len_min != 0:
            n = math.floor(len_maj / len_min)
            for idx, elem in reverse_enum(cl_maj):
                if idx % n != 0:
                    del X[elem]
                    del y[elem]

    Balance classes for binary classification. Perform in-place manipulation of array.
    :param X: list of feature vectors
    :param y: class labels (0 and 1)
    
Balance classes for binary classification. Perform in-place manipulation of array.
Balance classes for binary classification . Perform in - place manipulation of array .
def balance_class_sizes(X, y):
    with LogCont("Subsample majority class"):
        indices_of_classes = get_indices_of_classes(X, y)
        cl0 = indices_of_classes[0]
        if len(indices_of_classes) > 1:
            cl1 = indices_of_classes[1]
        else:
            cl1 = []
        if len(cl0) > len(cl1):
            len_maj = len(cl0)
            len_min = len(cl1)
            cl_maj = cl0
        else:
            len_maj = len(cl1)
            len_min = len(cl0)
            cl_maj = cl1
        if len_min != 0:
            n = math.floor(len_maj / len_min)
            for idx, elem in reverse_enum(cl_maj):
                if idx % n != 0:
                    del X[elem]
                    del y[elem]
def balance_class_sizes ( X , y ) : with LogCont ( "Subsample majority class" ) : indices_of_classes = get_indices_of_classes ( X , y ) cl0 = indices_of_classes [ 0 ] if len ( indices_of_classes ) > 1 : cl1 = indices_of_classes [ 1 ] else : cl1 = [ ] if len ( cl0 ) > len ( cl1 ) : len_maj = len ( cl0 ) len_min = len ( cl1 ) cl_maj = cl0 else : len_maj = len ( cl1 ) len_min = len ( cl0 ) cl_maj = cl1 if len_min != 0 : n = math . floor ( len_maj / len_min ) for idx , elem in reverse_enum ( cl_maj ) : if idx % n != 0 : del X [ elem ] del y [ elem ]
Balance classes for binary classification.
Balance classes for binary classification .
"""
    Balance classes for binary classification. Perform in-place manipulation of array.
    :param X: list of feature vectors
    :param y: class labels (0 and 1)
    """
X
list of feature vectors
list of feature vectors
y
class labels (0 and 1)
class labels ( 0 and 1 )