Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def transform_data(_data,_validate,_test,_target,encoding) :
if 'BinaryEncoding' in encoding['type'].keys():
ce_OHE = ce.BinaryEncoder(cols=encoding['type']['BinaryEncoding'])
_data = ce_OHE.transform(_data)
_test = ce_OHE.transform(_test)
_validate = ce_OHE.transform(_validate)
if 'TargetEncoding' in encoding['type'].keys():
# encoding of target is required
ce_LE = LabelEncoder()[_target].astype(str))
y = ce_LE.transform(_data[_target].astype(str))
ce_TE = ce.TargetEncoder(cols=encoding['type']['TargetEncoding']),y)
_data = ce_TE.transform(_data)
_test = ce_TE.transform(_test)
_validate = ce_TE.transform(_validate)
if 'OneHotEncoding' in encoding['type'].keys():
ce_OHE = ce.OneHotEncoder(cols=encoding['type']['OneHotEncoding'])
_data = ce_OHE.transform(_data)
_test = ce_OHE.transform(_test)
_validate = ce_OHE.transform(_validate)
return _data, _validate , _test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment