tabular_ml_toolkit/utility.py
def clip_splits(train,val,temp):
    """
    Fixes the stratification problem of StratifiedKfold
    Finds outstanding target values in train, valid splits and removes indexes of
    those train and valid splits from consideration for further correct definition of
    X_train,X_val,y_train,y_val
    """
    tr_target_unique=temp.iloc[train].target.unique()
    val_target_unique=temp.iloc[val].target.unique()

    if len(tr_target_unique) > len(val_target_unique):
        outstanding_target_class = list(set(tr_target_unique)- set(val_target_unique))
        ix_to_remove_from_train = []

        for i in outstanding_target_class:
            ix_to_remove_from_train.extend(temp.iloc[train].
                                           reset_index(drop=True).
                                           index[temp.target.iloc[train] == i].tolist())
            train = list(train)

        for index in sorted(ix_to_remove_from_train, reverse=True):
            del train[index]

    elif len(tr_target_unique) < len(val_target_unique):

        outstanding_target_class = list(set(val_target_unique)- set(tr_target_unique))
        ix_to_remove_from_val = []

        for i in outstanding_target_class:
            ix_to_remove_from_val.extend(temp.iloc[val].reset_index(drop=True).
                                         index[temp.target.iloc[val] == i].tolist())
        val = list(val)

        for index in sorted(ix_to_remove_from_val, reverse=True):
            del val[index]

    return train, val

    Fixes the stratification problem of StratifiedKfold
    Finds outstanding target values in train, valid splits and removes indexes of
    those train and valid splits from consideration for further correct definition of
    X_train,X_val,y_train,y_val
    
Fixes the stratification problem of StratifiedKfold
Finds outstanding target values in train, valid splits and removes indexes of
those train and valid splits from consideration for further correct definition of
X_train,X_val,y_train,y_val
Fixes the stratification problem of StratifiedKfold Finds outstanding target values in train valid splits and removes indexes of those train and valid splits from consideration for further correct definition of X_train X_val y_train y_val
def clip_splits(train,val,temp):
    tr_target_unique=temp.iloc[train].target.unique()
    val_target_unique=temp.iloc[val].target.unique()
    if len(tr_target_unique) > len(val_target_unique):
        outstanding_target_class = list(set(tr_target_unique)- set(val_target_unique))
        ix_to_remove_from_train = []
        for i in outstanding_target_class:
            ix_to_remove_from_train.extend(temp.iloc[train].
                                           reset_index(drop=True).
                                           index[temp.target.iloc[train] == i].tolist())
            train = list(train)
        for index in sorted(ix_to_remove_from_train, reverse=True):
            del train[index]
    elif len(tr_target_unique) < len(val_target_unique):
        outstanding_target_class = list(set(val_target_unique)- set(tr_target_unique))
        ix_to_remove_from_val = []
        for i in outstanding_target_class:
            ix_to_remove_from_val.extend(temp.iloc[val].reset_index(drop=True).
                                         index[temp.target.iloc[val] == i].tolist())
        val = list(val)
        for index in sorted(ix_to_remove_from_val, reverse=True):
            del val[index]
    return train, val
def clip_splits ( train , val , temp ) : tr_target_unique = temp . iloc [ train ] . target . unique ( ) val_target_unique = temp . iloc [ val ] . target . unique ( ) if len ( tr_target_unique ) > len ( val_target_unique ) : outstanding_target_class = list ( set ( tr_target_unique ) - set ( val_target_unique ) ) ix_to_remove_from_train = [ ] for i in outstanding_target_class : ix_to_remove_from_train . extend ( temp . iloc [ train ] . reset_index ( drop = True ) . index [ temp . target . iloc [ train ] == i ] . tolist ( ) ) train = list ( train ) for index in sorted ( ix_to_remove_from_train , reverse = True ) : del train [ index ] elif len ( tr_target_unique ) < len ( val_target_unique ) : outstanding_target_class = list ( set ( val_target_unique ) - set ( tr_target_unique ) ) ix_to_remove_from_val = [ ] for i in outstanding_target_class : ix_to_remove_from_val . extend ( temp . iloc [ val ] . reset_index ( drop = True ) . index [ temp . target . iloc [ val ] == i ] . tolist ( ) ) val = list ( val ) for index in sorted ( ix_to_remove_from_val , reverse = True ) : del val [ index ] return train , val
Fixes the stratification problem of StratifiedKfold
Finds outstanding target values in train, valid splits and removes indexes of
those train and valid splits from consideration for further correct definition of
X_train,X_val,y_train,y_val
Fixes the stratification problem of StratifiedKfold Finds outstanding target values in train valid splits and removes indexes of those train and valid splits from consideration for further correct definition of X_train X_val y_train y_val
"""
    Fixes the stratification problem of StratifiedKfold
    Finds outstanding target values in train, valid splits and removes indexes of
    those train and valid splits from consideration for further correct definition of
    X_train,X_val,y_train,y_val
    """
train
val
temp