def replace_with_woe(train_data, test_data, exclude_var, target='target'): all_var = train_data.columns.tolist() for var in all_var: if var not in exclude_var and is_object_dtype(train_data[var]): woe = WOETransformer().fit(train_data[var], train_data[target]) train_data[var] = woe.transform(train_data[var]) train_data[var].astype('float64') test_data[var] = woe.transform(test_data[var]) test_data[var].astype('float64') return train_data, test_data
def test_woe_transformer_with_unknown_group(): transer = WOETransformer().fit(str_feat, target) res = transer.transform(['Z'], default = 'min') assert res[0] == -0.2198594761130199