how to assign back categorical variables to train and test data after training and testing using inverse_transform?

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.

Topic feature-engineering scikit-learn machine-learning

Category Data Science


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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.