0
$\begingroup$

how to assign back categorical variables to train and test data after training and testing using inverse_transform? Like training and testing, data will have encoded numerical values. So, how to assign back categorical values to those variables to train and test dataset after training and testing? Please help me with this.

$\endgroup$
0
$\begingroup$

If you are using ordinal data

Use this to encode

  
from sklearn.preprocessing import OrdinalEncoder
oe=OrdinalEncoder()
social['Gender']=oe.fit_transform(social[['Gender']])

Use this to decode

social['Gender']=oe.inverse_transform(social[['Gender']])


If you are using nominal variables

Use this to encode

from sklearn.preprocessing import OneHotEncoder
  
ohe = OneHotEncoder()

temp_var= ohe.fit_transform(social[['Gender']]) 

Use this to decode

temp_var2=ohe.inverse_transform(temp_var)

Hope it helps

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.