Skip to content

Instantly share code, notes, and snippets.

Embed
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'])
ce_OHE.fit(_data)
_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()
ce_LE.fit(_data[_target].astype(str))
y = ce_LE.transform(_data[_target].astype(str))
ce_TE = ce.TargetEncoder(cols=encoding['type']['TargetEncoding'])
ce_TE.fit(_data,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'])
ce_OHE.fit(_data)
_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
You can’t perform that action at this time.